- Newest
- Most votes
- Most comments
If you want to send notifications to the client, you will need to create a WebSockets API. The client will connect to the API, and you will need to record the connection ID for the users, usually, in a DynamoDB table. You do that from a Lambda function integrated with the $connect integration in the API.
When you want to send a message to the client, you will need to find the connection ID for the user, and use the API Gateway's postToConnection API to send the message to the client. If the message is coming from SNS, you will probably invoke a Lambda function that will get the message from SNS and send to API Gateway. You can't configure SNS to send the messages directly to the postToConnection API.
Hi, you can refer to ServerlessLand example here: https://serverlessland.com/patterns/apigw-websocket-api-sns This example covers how to use SNS with WebSocket API along with request validation
Relevant content
- asked a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 4 months ago
Thanks. I thought if I got this working I could figure out how to pass the connection ID along with the SNS message, and avoid the need for intervening Lambda. I only need the connection long enough to generate a single response from downstream of the SNS message.
In order to make a call to the postToConnection API you need to sign the request with AWS credentials that you get from an IAM Role. SNS doesn't know how to do it when making an HTTP request. When you invoke a Lambda function, with the appropriate IAM Role, the SDK that you use in the code, will sign the request going to API Gateway.