简体   繁体   中英

How to schedule on-demand tasks on aws serverless

We are developing a serverless application on AWS. Currently, we have a use case in which we want a user to be able to create configurations for schedules to send them daily, weekly or monthly reports at a specific time on the day on which the report will be sent. We have multiple users, and each user can have multiple report schedule configurations.

I want to know, What is the best architecture for this feature on a serverless application on AWS?

My initial thoughts were to make a table in DB that holds the details of the schedules for each user and make an event rule which runs every minute to trigger a lambda function which checks this table and see if there are any jobs at this time to be triggered or not. and if there is any schedule at this time, it will send the report. But my leader had a concern for this solution as this solution is hitting the DB recurrently and this is a load on DB (we are using aurora MySQL).

I'm not sure about what scale will you be operating. But I think you can use cloudwatch events which ultimately triggers the lambda function.

So your user's configuration can become a cloudwatch event with its specific rule and whenever the rule executes it triggers the lambda function.

I'd suggest you to go through this:

https://aws.amazon.com/blogs/mt/build-scheduler-as-a-service-amazon-cloudwatch-events-amazon-eventbridge-aws-lambda/

Looks like it's exactly what you are looking for.

Recently(10-Nov-2022) AWS launched a new service called EventBridge Scheduler and it's serverless. I think this is what you are looking for. Mainly in the schedule patterns, you can choose,

  • One-time Schedule
  • 在此处输入图像描述


  • Recurring Schedule
  • In the recurring schedule, you have two schedule types.

    1. Cron-based schedule
    2. Rate-based schedule

    1. Cron-based schedule

    在此处输入图像描述

    2. Rate-based schedule

    在此处输入图像描述

    For both options in Recurring Schedule , you can set the Timeframe as well.

    在此处输入图像描述

    The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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