Select your cookie preferences

We use cookies and similar tools to enhance your experience, provide our services, deliver relevant advertising, and make improvements. Approved third parties also use these tools to help us deliver advertising and provide certain site features.

API Gateway WebSocket API to AWS Lambda

Created with SnapAPI Gateway WebSocket APIAWS Lambda

Create an Amazon API Gateway Websocket API that invokes an AWS Lambda function

This pattern deploys an Amazon API Gateway WebSocket API with a $connect route, a $disconnect route and a custom route.
The $connect route invokes an AWS Lambda function to record the WebSocket's connection ID to a DynamoDB table.
The custom route is integrated with an AWS Lambda function written in Node.js which returns back the contents of the "data" node of a JSON object within the request's body. The $disconnect route invokes a Lambda function to remove the connection ID from the DynamoDB table when the WebSocket connection is closed.

< Back to all patterns


GitHub icon Visit the GitHub repo for this pattern.

Launch Stack

Download

git clone https://github.com/aws-samples/serverless-patterns/ cd serverless-patterns/apigw-websocket-api-lambda

Deploy

sam deploy --guided


Testing

See the repo for detailed testing instructions.

Cleanup

1. Delete the stack: sam delete --stack-name STACK_NAME.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"

Joe Tringali

Presented by Joe Tringali

Joe is a Solutions Architect with the Northeast Greenfield team at Amazon Web Services and a Serverless enthusiast.