Home > Net >  Websocket API not returning answers AWS
Websocket API not returning answers AWS

Time:10-19

I have a very simple Websocket API hosted in AWS.
I am integrated this API with a Lambda function whose code is :

import json


def lambda_handler(event, context):
    print(event)
    return {
        "isBase64Encoded": False,
        "statusCode": 200,
        "headers": {"Content-Type": "application/json"},
        "body": json.dumps(event)
    }

I have also added integration response for a two-way communication as stated in this result

As you can see, i am connected successfully and if i write an existing route from the request.body.action selection (sendMessage), there is no error but there is no output. If i write a wrong route (test that i have not created in the API Gateway console), i have got an error message.

I have also tried with more simple outputs from the function, none is working. I have finally wrote the above code as stated in this enter image description here

Here is a screenshot about the permission of the Lambda. By the way, these are the permissions for all of my Lambdas (under HTTP APIs) that all work fine :

permissions

CodePudding user response:

It seems like your Lambda function does not have permission to post message to API Gateway connections. Try giving your Lambda function permission for action execute-api:ManageConnections on the API Gateway resource.

CodePudding user response:

I have figured out what was wrong.

I was used to have an automated stage deployment with my HTTPs APIs and i simply did not deployed changes.
I add that i had to recreated a fresh Websocket API to be sure and i confirm that i was as simple as that.

Hope this helps others !

  • Related