Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New serverless pattern eventbridge-schedule-to-batch-terraform #1460

Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions eventbridge-schedule-to-batch-terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# terraform

/.terraform
/terraform.lock.hcl
*.tfstate*
*.tfstate.backup
*.tfvars
54 changes: 54 additions & 0 deletions eventbridge-schedule-to-batch-terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Amazon EventBridge Scheduler to AWS Batch

This pattern will create an [EventBridge Scheduler](https://docs.aws.amazon.com/scheduler/latest/UserGuide/getting-started.html) to submit an [AWS Batch](https://docs.aws.amazon.com/batch/latest/userguide/Batch_GetStarted.html) job from a job definition every 5 minutes. The pattern is deployed using Terraform to create the required VPC, Batch and EventBridge Scheduler resources.

Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/eventbridge-schedule-to-batch-terraform

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

## Requirements

* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
* [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) installed

## Deployment Instructions

1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
```
git clone https://github.com/aws-samples/serverless-patterns
```
1. Change directory to the pattern directory:
```
cd serverless-patterns/eventbridge-schedule-to-batch-terraform
```
1. From the command line, initialize Terraform:
```
terraform init
```
1. From the commend line, apply the configuration in the main.tf file and follow the prompts:
```
terraform apply
```


## How it works

An Amazon EventBridge Schedule is created that submits an AWS Batch job from a job definition every 5 minutes. The Terraform stack creates a VPC, Batch compute environment, jobs and job queues, and EventBridge Scheduler that invokes the submitJob API to run the AWS Batch job.

## Testing

1. After deployment, view the schedule created in the Amazon EventBridge console under Scheduler>Schedules.
2. From the AWS Batch console, navigate to the Jobs section. The schedule will trigger a new job every 5 minutes, which will be visable in the Jobs section. You can also view the job status from the Dashboard section of the AWS Batch console in the Job queue overview.

## Cleanup

1. Delete all created resources and follow prompts:
```
terraform destroy
```
----
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0
57 changes: 57 additions & 0 deletions eventbridge-schedule-to-batch-terraform/example-pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"title": "Amazon EventBridge Scheduler to AWS Batch",
"description": "Schedule AWS Batch jobs using Amazon EventBridge Scheduler",
"language": "",
"level": "200",
"framework": "Terraform",
"introBox": {
"headline": "How it works",
"text": [
"This sample project demonstrates how to use Amazon EventBridge Scheduler to schedule batch compute jobs with AWS Batch. This pattern leverages universal targets with EventBridge Scheduler to talk directly to Batch, which uses only JSON_based, structured language to define the implementation.",
"This pattern deploys one VPC, EventBridge Scheduler Schedule, one Batch compute environment, Batch Job and Queue."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/eventbridge-schedule-to-batch-terraform",
"templateURL": "serverless-patterns/eventbridge-schedule-to-batch-terraform",
"projectFolder": "eventbridge-schedule-to-batch-terraform",
"templateFile": "eventbridge-schedule-to-batch-terraform/main.tf"
}
},
"resources": {
"bullets": [
{
"text": "Amazon EventBridge Scheduler",
"link": "https://docs.aws.amazon.com/eventbridge/latest/userguide/scheduler.html"
},
{
"text": "AWS Batch",
"link": "https://docs.aws.amazon.com/batch/latest/userguide/what-is-batch.html"
}
]
},
"deploy": {
"text": [
"terraform apply"
]
},
"testing": {
"text": [
"See the Github repo for detailed testing instructions."
]
},
"cleanup": {
"text": [
"Delete the stack: <code>terraform destroy</code>."
]
},
"authors": [
{
"name": "Ian Lodge",
"image": "https://avatars.githubusercontent.com/u/135351711?v=4",
"bio": "Ian is a Solutions Architect at Amazon Web Services based in the US.",
"linkedin": "https://www.linkedin.com/in/ian-lodge"
}
]
}
Loading