简体   繁体   English

AWS lambda 或 AWS 批处理根据特定标准从发电机数据库中删除行

[英]AWS lambda or AWS batch to delete rows from dynamo DB based on certain criteria

I have a requirement where I need to delete records based on criteria it doesn't need to be real time, the records are stored in dynamo DB.我有一个要求,我需要根据不需要实时的标准删除记录,记录存储在发电机数据库中。 Can AWS lambda be scheduled ex run every day @ 11pm can I package a cron job or is it better to go with AWS batch only worry with batch is it has more overheads. AWS lambda 可以安排在每天晚上 11 点前运行我可以 package 一个 cron 作业还是 go 更好。

Thanks谢谢

If your criteria is time then the best option is to use the Time To Live (TTL).如果您的标准是时间,那么最好的选择是使用生存时间 (TTL)。 DynamoDB TTL feature delete a records after expiry. DynamoDB TTL 功能在过期后删除记录。

TTL is useful if you store items that lose relevance after a specific time.如果您存储在特定时间后失去相关性的项目,TTL 很有用。 The following are example TTL use cases:以下是 TTL 用例示例:

  • Remove user or sensor data after one year of inactivity in an application.在应用程序中一年不活动后删除用户或传感器数据。
  • Archive expired items to an Amazon S3 data lake via Amazon DynamoDB Streams and AWS Lambda.通过 Amazon DynamoDB Streams 和 AWS Lambda 将过期项目存档到 Amazon S3 数据湖。
  • Retain sensitive data for a certain amount of time according to contractual or regulatory obligations.根据合同或监管义务将敏感数据保留一段时间。

AWS provides details in this document . AWS 在本文档中提供了详细信息。

If instead you have more complex criteria, you could use Lambda as you requested, however creating a Lambda function alone won't be enough.相反,如果您有更复杂的标准,则可以按照您的要求使用 Lambda,但是仅创建 Lambda function 是不够的。 In fact Lambda need always something to kick it off, like a cron job.事实上,Lambda 总是需要一些东西来启动它,比如 cron 工作。 AWS recommends to use CloudWatch to schedule Lambda runs. AWS 建议使用 CloudWatch 来安排 Lambda 运行。 Relevant documentation can be found in the tutorial " Schedule AWS Lambda Functions Using CloudWatch Events " This process includes the following steps:相关文档可在教程“ 使用 CloudWatch Events 调度 AWS Lambda 函数”中找到。该过程包括以下步骤:

  1. Create an AWS Lambda Function to log the scheduled events.创建 AWS Lambda Function以记录计划的事件。 Specify this function when you create your rule.创建规则时指定此 function。

  2. Create a rule in CloudWatch to run your Lambda function on a schedule.在 CloudWatch 中创建规则以按计划运行 Lambda function。 A rule would look like:规则如下所示:

    aws events put-rule aws 事件放置规则
    --name my-scheduled-rule --name my-scheduled-rule
    --schedule-expression 'rate(5 minutes)' --schedule-expression '速率(5 分钟)'

  3. Verify the rule checking that your Lambda function was invoked.验证规则检查您的 Lambda function 是否被调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM