- Newest
- Most votes
- Most comments
Oh, I see. You're asking how to run your Lambda periodically like cron job.
First, you have to use $connect route to store connectionIds to somewhere (e.g. DynamoDB).
There would be multiple ways to execute Lambda periodically, but an easiest way would be using CloudWatch event to trigger your Lambda.
https://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html
Your Lambda function needs to retrieve connectionIds, then iterate to invoke pushToConnection to each connectionId. You may use HTTP/2 streaming to send multiple requests same time.
Hello,
Can anybody please advise on this issue?
Thanks
Edited by: KrishnaMK on Mar 27, 2019 4:05 AM
You can use @connections API to send a message from your backend service.
Here is a API in SDKs:
Java SDK
https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/apigatewaymanagementapi/AmazonApiGatewayManagementApiClient.html#postToConnection-com.amazonaws.services.apigatewaymanagementapi.model.PostToConnectionRequest-
JavaScript SDK
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ApiGatewayManagementApi.html#postToConnection-property
Please take a look at an example to use postToConnection (written in JavaScript)
https://github.com/aws-samples/simple-websockets-chat-app/blob/master/sendmessage/app.js
Many thanks for your response, we are using PostToConnection method mentioned to respond back when a client request comes in. However the issue is that as we are working with a full server-less architecture using AWS Lambda and we don't have the 'back-end service' to trigger messages from as and when we want. Does this makes sense, please let us know your comments?
Thank you very much jwaataws!!! I think this is what we were looking for, highly appreciate your quick and great response!!!
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago