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

gefragt vor 5 Jahren483 Aufrufe
5 Antworten
0
Akzeptierte Antwort

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
beantwortet vor 5 Jahren
profile picture
EXPERTE
überprüft vor einem Monat
0

Hello,

Can anybody please advise on this issue?

Thanks

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

beantwortet vor 5 Jahren
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?

beantwortet vor 5 Jahren
0

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

beantwortet vor 5 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen