I am using WebSocket ApiGateway with AWS Lambda integration. When I try to post data to a client with post_to_connection
method of boto3.client('apigatewaymanagementapi')
the Lambda function always times out without any error message. Only the timeout message gets logged in CloudWatch:
Task timed out after 3.00 seconds
My code:
import json
import boto3
import time
import urllib
api_client = boto3.client('apigatewaymanagementapi')
def lambda_handler(event, context):
connectionId = event['requestContext']['connectionId']
api_client.post_to_connection(ConnectionId=connectionId, Data=json.dumps({'test': '1'}))
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
What am I doing wrong?