API WebSocket to Amazon SNS with request validation

Amazon API Gateway → Amazon SNS

Create a WebSocket API to send notification via SNS topic with request validation

This sample project demonstrates how to use an Amazon API Gateway WebSocket API to integrate with Amazon Simple Notification service (SNS) to send notifications. This pattern also implements data validation in the WebSocket API using a model in API Gateway.
This pattern is utilizing native AWS Integration between WebSocket API Gateway and SNS. A request template is used in WebSocket integration to map the input to SNS payload.
This pattern is also a workaround to invoke AWS services in WebSocket API which requires the Content-Type header to be application/x-www-form-urlencoded. By default, WebSocket APIs do not support overriding headers from AWS console.
This pattern deploys one API Gateway and one SNS topic.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

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

Deploy

terraform initterraform apply


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

terraform destroy -target aws_apigatewayv2_route.send_order
terraform destroy
terraform show

Created by:

Dushyant Pal

Dushyant Pal

Cloud Engineer, Serverless team at AWS Sydney, Australia

Follow on LinkedIn