0

Details: I have a web app on Elastic Beanstalk (web server) and I need several cronjobs to be executed in PHP. These cronjobs must connect to AWS RDS. For this, I created an Elastic Beanstalk Worker but I must pay for the worker instance to be available all day when cronjobs only need 20 minutes maximum each.

1

2 Answers 2

3

You can use Batch for longer running job, or Lambda for shorter jobs (less than 5 minutes). Batch and Lambda are both valid CloudWatch Event Targets, so you don't need to use both to trigger a cron job.

For Batch (long running):

In the CloudWatch Events console, setup a scheduled task (cron), and for the target, configure your Batch job. CloudWatch will make the SubmitJob API call on your behalf. https://docs.aws.amazon.com/batch/latest/userguide/batch-cwe-target.html

For Lambda (short running):

In the CloudWatch Events console, setup a scheduled task (cron), and for the target, specify your Lambda function. CloudWatch will trigger the Lambda function automatically. https://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html

2

Short answer: CloudWatchEvent -> Lambda fn -> AWS Batch Job

Long answer: Create a scheduled cloudwatch event, which triggers at specific time. configure a lambda function to trigger on this event. This lambda function will queue a Job with AWS Batch (pre-configure the job-queue and related items). This Job needs to specify the cron-job you want to run.

Cloudwatch, lambda and AWS Batch is practically free in this case, so the only cost involved is running your ec2 instance for the duration of your job. Hope this helps!

0

You must log in to answer this question.