Amazon API Gateway WebSocket API to AWS Lambda

API Gateway WebSocket API → AWS 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 Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Launch Stack

Clone repo

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"

Created by:

Joe Tringali

Joe Tringali

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