Websocket issue - sync server time with javascript time

0

Hello,

We have implemented API Gateway web socket (with serverless AWS Lambda) and it works well. However, we have encountered a critical issue explained below and would highly appreciate if anybody can provide a solution / workaround:

  • We want to sync server time with client/javascript time and wanted to use web sockets to send timestamp to all connected clients at regular intervals. However, we found that without an input action from a client, we cannot push data to the clients automatically. Is this understanding correct? If yes, is there any workaround for this issue, as we are using serverless architecture with AWS Lambda?

Thanks in advance,
Krishna

asked 5 years ago471 views
5 Answers
0
Accepted Answer

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.

AWS
answered 5 years ago
profile picture
EXPERT
reviewed a month ago
0

Hello,

Can anybody please advise on this issue?

Thanks

Edited by: KrishnaMK on Mar 27, 2019 4:05 AM

answered 5 years ago
0

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?

answered 5 years ago
0

Thank you very much jwaataws!!! I think this is what we were looking for, highly appreciate your quick and great response!!!

answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions