Bobcares

AWS Batch as a target for EventBridge rule

by | Jan 29, 2022

Wondering how to use AWS Batch as a target for EventBridge rule? We can help you.

Here, at Bobcares, we assist our customers with several AWS queries as part of our AWS Support Services.

Today, let us see steps followed by our Support Techs in this query.

How to use AWS Batch as a target for EventBridge rule?

Today, let us see the steps followed by our Support Techs to configure Amazon EventBridge to submit an AWS Batch job.

Create a job definition

1.    Firstly, open the AWS Batch console.

2.    From the navigation bar, select your AWS Region.

3.    In the navigation pane, choose Job definitions, and then choose Create.

4.    For Job definition name, enter a unique name for your job definition.

Note: You can use up to 128 letters (uppercase and lowercase), numbers, hyphens, and underscores in your unique name.

5.    For Container image, enter amazonlinux.

6.    For Command, enter the following:

echo Ref::S3bucket

7.    For vCPUs, enter 2.

8.    For Memory (MiB), enter 500.

9.    Choose Next, and then choose Create.

Get the ARN of your job queue and job definition

1.    Firstly, open the AWS Batch console.

2.    In the navigation pane, choose Job queues.

3.    Then, choose your job queue.

4.    In the Job queue details section, copy the Queue ARN, and then save it for later.

5.    In the navigation pane, choose Job definitions, and then choose the job definition that you previously created.

6.    In the Job definition details section, copy the Job definition ARN, and then save it for later.

Create the EventBridge rule

1.    Firstly, open the EventBridge console.

2.    Then, select Create rule.

3.    Enter a Name for your rule. You can optionally enter a Description.

4.    In Define pattern, select Event pattern.

5.    Select Pre-defined pattern by service.

6.    For Service provider, choose AWS.

7.    For Service name, choose Simple Storage Service (S3).

8.    For Event type, choose Bucket-Level API Call via CloudTrail.

9.    Finally, choose Any operation.

Test the new rule that you created

1.    Firstly, open the Amazon S3 console.

2.    Then, choose Create bucket.

3.    In the Bucket name field, type a unique DNS-compliant name for your new bucket.

4.    For Region, choose the same Region where you created the EventBridge rule.

5.    Finally, choose Create.

Create the EventBridge rule

1.    Firstly, open the EventBridge console.

2.    Then, select Create rule.

3.    Next, enter a Name for your rule. You can optionally enter a Description.

4.    In Define pattern, select Event pattern.

5.    Then, select Pre-defined pattern by service.

6.    For Service provider, choose AWS.

7.    For Service name, choose Simple Storage Service (S3).

8.    For Event type, choose Bucket-Level API Call via CloudTrail.

9.    Next, choose Any operation.

10.    In the Select targets section, choose Batch job queue from the Target dropdown list.

11.    For Job queue, paste in the job queue ARN that you copied earlier.

12.    For Job definition, paste in the job definition ARN that you copied earlier.

13.    For Job name, enter a name for your AWS Batch job.

14.    In the Configure input section, choose Input Transformer.

15.    In the first input box, enter the S3 bucket values to be sent when the event is triggered:

{"S3BucketNameValue":"$.detail.requestParameters.bucketName"}

Note: Replace S3BucketNameValue with your own value.

16.    In the second input box, enter the Parameters structure to be passed to the Batch job:

{"Parameters" : {"S3bucket": S3BucketNameValue}}

Note: Replace S3BucketNameValue with your own value. Replace S3bucket with the name of the parameter that you want to define in your AWS Batch job.

17.    Choose either Create a new role for this specific resource or Use existing role.

Note: If you choose an existing role, that role should have an AWS Identity and Access Management (IAM) policy that allows the batch:SubmitJob action.

18.    Finally, select Create.

Test the new rule that you created

1.    Firstly, open the Amazon S3 console.

2.    Then, choose Create bucket.

3.    In the Bucket name field, type a unique DNS-compliant name for your new bucket.

4.    For Region, choose the same Region where you created the EventBridge rule.

5.    Finally, choose Create.

Check your logs

1.    Firstly, open the AWS Batch console.

2.    In the navigation pane, choose Jobs.

3.    Then, choose your job with a Status of SUCCEEDED.

4.    On the Job details page, in the Attempts section, choose View logs. The log displays your bucket name in the CloudWatch console.

[Need help with the procedure? We’d be glad to assist you]

Conclusion

In short, we saw how our Support Techs use AWS Batch as a target for EventBridge rule

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.