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

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ