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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则