Home > front end >  Editable scheduled tasks in cloud
Editable scheduled tasks in cloud

Time:06-06

I'm using API Gateway with Web sockets to implement a chat server. I'm storing all the messages in current session in Redis (AWS Elasticache).

API gateway websocket -> SQS(FIFO) -> Lambda(For processing) -> Elasticache.

I want to implement timeout functionality. If 20 minutes have passed since last message then move the data from redis to sql.

How can I achieve this on AWS?

CodePudding user response:

The approach I would take would be to have a last message key pair stored in your redis server with a timestamp and would update with every message. Something like:

KEY                    VALUE
---------------------------------------------------
lastmessage            1654371394

I would then have lambda function that checked that value and if the timestamp is over 20 minutes, do the redis to sql logic. I would then create a cloudwatch scheduled event that would trigger the lambda function every minute.

This article explains how:

https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html

  • Related