Porting to aws-cdk ( in python ).
See original GitHub issueI have been attempting to port this chat-app to a aws-cdk application, and feel like i’m close, but not quite there yet.
This is the response i’m getting `[ec2-user@ip-172-31-x-x websocket]$ wscat -c wss://xxxxxxx.execute-api.ap-southeast-2.amazonaws.com/prod Connected (press CTRL+C to quit)
{“action”:“sendmessage”,“data”:“hello world”} < {“message”: “Internal server error”, “connectionId”:“VNRUSeldSwMCIRQ=”, “requestId”:“VNRXVFJOywMF3-Q=”}`
I know that the message is arriving at the lambda associated with the sendmessage lambda. I’m able to to print it and see it in the lambda logs. I’m getting a client error when it trys to post_connection.
ERROR] EndpointConnectionError: Could not connect to the endpoint URL: "https://execute-api.ap-southeast-2.amazonaws.com/@connections/VNmugd9KSwMCFwQ%3D"
I have attempted to reduce my lambda down to a simple as seems sensible. Just to try and diganose the issue, i also gave the lambda function full administrative permissions, but that made no difference either.
Heres the labmda code.
import boto3
import os
from botocore.exceptions import ClientError
import json
def lambda_handler(event, context):
message = 'one two three'.encode('utf-8')
body = event['body']
print(body)
connectionId = event['requestContext']['connectionId']
print(connectionId)
api_client = boto3.client('apigatewaymanagementapi')
api_client.post_to_connection(
Data = message,
ConnectionId = connectionId
)
return {
'statusCode': 200,
'body': 'Message Sent'
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6
Top GitHub Comments
I’m also trying to use websocket with CDK. Your code helped me a lot !
I created this repository if you want :
https://github.com/tuanardouin/WebSocket-CDK
There is a bug / error in the Boto3 documentation!!! The boto3 client docs dont’ say how to specifiy the url! I foudn this issue in the boto github issues, its been an issue for nearly 2 years with multiple people hitting the same issue! Minor change to the lambda…
My problem is resolved.