首页 > 解决方案 > AWS: Execute a task after 1 year has elapsed

问题描述

Basically, I have a web service that receives a small json payload (an event) a few times per minute, say 60. This event must be sent to an SQS queue only after 1 year has elapsed (it's ok to have it happen a few hours sooner or later, but the day of month should be exactly the same).

This means I'll have to store more than 31 million events somewhere before the first one should be sent to the SQS queue.

I thought about using SQS message timers, but they have a limit of only 15 minutes, and as pointed out by @Charlie Fish, it's weird to have an element lurking around on a queue for such a long time.

A better possibility could be to schedule a lambda function using a Cron expression for each event (I could end up with millions or billions of scheduled lambda functions in a year, if I don't hit an AWS limit well before that).

Or I could store these events on DynamoDB or RDS.

What would be the recommended / most cost-effective way to handle this using AWS services? Scheduled lambda functions? DynamoDB? PostgreSQL on RDS? Or something entirely different?

And what if I have 31 billion events per year instead of 31 million?

I cannot afford to loose ANY of those events.

标签: amazon-web-servicesamazon-sqs

解决方案


DynamoDB 是一个合理的选择,RDS 也是如此——用于长期存储的 SQS 不是一个好的选择。但是 - 如果您想降低成本,我可能会建议另一个:在单个 24 小时期间(或者如果需要,可以更小的间隔)累积事件,并将该组数据作为 S3 对象写出,而不是保留它在 DynamoDB 中。您可以使用 dynamodb 或 rds(或其他任何东西)作为累积一天(或一小时)的事件的地方,然后将这些数据作为间隔的一组数据写入 S3。

每个 S3 对象都可以适当命名,或者指示它创建的日期/时间,或者它需要使用的数据/时间,即 20190317-1400 以指示 2019 年 3 月 17 日下午 2 点需要使用此文件。

我会想象一个 lambda 函数,由每 60 分钟触发一次的 cloudwatch 事件调用,它会扫描您的 s3 存储桶以查找将要使用的文件,然后读取 json 数据并将它们放入 SQS 队列以供进一步使用处理并将已处理的 s3 对象移动到另一个“已处理”存储桶

您的存储成本将是最低的(特别是如果您按天或按小时对它们进行批量处理),S3 具有 11 个 9 的持久性,并且您可以将较旧的事件存档到 Glacier,即使在处理完这些事件之后您也想保留它们。

DynamoDB 是一款很棒的产品,它提供冗余存储和超高性能——但我认为您的要求中没有任何内容可以保证产生该成本或需要 DynamoDB 的性能;以及为什么在您提前知道一年后不需要使用或查看记录时将数百万条数据记录保存在“始终在线”的数据库中。


推荐阅读