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

已提問 5 年前檢視次數 483 次
5 個答案
0
已接受的答案

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
已回答 5 年前
profile picture
專家
已審閱 1 個月前
0

Hello,

Can anybody please advise on this issue?

Thanks

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

已回答 5 年前
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?

已回答 5 年前
0

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

已回答 5 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南