9

We are looking for aws batch job and we want to submit this batch job on a certain predefined interval. For e.g.: we want to auto submit this job every 4 hours.

What could be a preferred way to achieve it.

Rahul Garg
  • 4,069
  • 1
  • 34
  • 31

1 Answers1

34

You can use Cloudwatch to schedule Batch jobs. In the Cloudwatch console:

  1. Click on Rules
  2. Click on the blue "Create rule" button
  3. Click the "Schedule" radio button
  4. Change the fixed rate to 4 hours, or you can use a cron expression
  5. On the right side of the screen add a target of batch job, fill in the queue, job name, job definition, etc.

We use this for all of our batch jobs, works very well.

doug
  • 361
  • 3
  • 4
  • is there any way to add os environment variable when we submit batch-job via cloudwatch – Maulik Harkhani Mar 09 '20 at 09:57
  • Indeed you can! Give this doc a read through: https://aws.amazon.com/premiumsupport/knowledge-center/batch-parameters-trigger-cloudwatch/ Longer answer: In your CloudWatch rule, choose to configure a custom input. Choose the "Constant (JSON text)" option and enter something like: {"Parameters": {"name":"test"}, "ContainerOverrides": { "Command": ["echo","Ref::name"] } } – Travis Bell Apr 27 '21 at 15:12
  • is there a way to invoke the job directly without submitting it to the job queue? as far as I understood, the cloudwatch schedule settings specify the time of submitting the job to the queue, while the actual execution may happen at some indefinite time – mangusta Aug 01 '21 at 20:38
  • 2
    Nowadays Cloudwatch rules are called Amazon EventBridge, for the ones that one to avoid some searches... – camikiller Feb 05 '22 at 04:19
  • 1
    AWS doc link, similar to this answer - https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html Also check this - https://docs.aws.amazon.com/batch/latest/userguide/batch-cwe-target.html – Ritesh May 17 '23 at 18:01