Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions sfn-manage-batch-job-tf/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Manage a Batch Job

This workflow use Step Functions, AWS Batch and AWS SNS Topics to start an batch job and send a notification with the status of the job execution via SNS. This sample project creates the following:
This workflow use Step Functions, AWS Batch and Amazon SNS Topics to start an batch job and send a notification with the status of the job execution via SNS. This sample project creates the following:

* An AWS Batch job
* An Amazon SNS topic
* AWS Step Function
* AWS Step Functions
* Related AWS Identity and Access Management (IAM) roles

Learn more about this workflow at Step Functions workflows collection: https://docs.aws.amazon.com/step-functions/latest/dg/batch-job-notification.html
Expand All @@ -16,7 +16,7 @@ Important: this application uses various AWS services and there are costs associ
* [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)
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
* [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli) with version 1.x installed (this pattern has been tested with version 1.15)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This pattern use Terraform not AWS SAM!


## Deployment Instructions

Expand Down
27 changes: 18 additions & 9 deletions sfn-manage-batch-job-tf/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~>4.0"
version = "~> 6.0"
}
}
}
Expand Down Expand Up @@ -218,7 +218,11 @@ resource "aws_iam_role" "batch_role" {
},
]
})
managed_policy_arns = ["arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

│ Warning: Argument is deprecated
│
│   with aws_iam_role.batch_role,
│   on main.tf line 221, in resource "aws_iam_role" "batch_role":
│  221:   managed_policy_arns = ["arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"]
│
│ managed_policy_arns is deprecated. Use the aws_iam_role_policy_attachment resource instead. If Terraform should exclusively manage all managed policy attachments (the current behavior of this argument), use the
│ aws_iam_role_policy_attachments_exclusive resource as well.
│
│ (and one more similar warning elsewhere)
╵

}

resource "aws_iam_role_policy_attachment" "batch_role" {
role = aws_iam_role.batch_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"
}

#Create the ECS instance role
Expand All @@ -236,7 +240,11 @@ resource "aws_iam_role" "batch_ecs_role" {
},
]
})
managed_policy_arns = ["arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"]
}

resource "aws_iam_role_policy_attachment" "batch_ecs_role" {
role = aws_iam_role.batch_ecs_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}

# Create the ECS instance profile
Expand All @@ -246,7 +254,7 @@ resource "aws_iam_instance_profile" "ecs_profile" {
}

resource "aws_batch_compute_environment" "batch_compute_env" {
compute_environment_name = "BatchComputeEnvironment-${random_string.random.result}"
name = "BatchComputeEnvironment-${random_string.random.result}"
type = "MANAGED"
service_role = aws_iam_role.batch_role.arn
compute_resources {
Expand All @@ -264,20 +272,21 @@ resource "aws_batch_compute_environment" "batch_compute_env" {
]
}
depends_on = [
aws_iam_role.batch_ecs_role,
aws_iam_role_policy_attachment.batch_ecs_role,
aws_subnet.subnet,
aws_security_group.batch_sg,
aws_iam_role.batch_role
aws_iam_role_policy_attachment.batch_role
]
}

resource "aws_batch_job_queue" "batch_job_queue" {
name = "StepFunctions-BatchJobManagementQueue-${random_string.random.result}"
state = "ENABLED"
priority = 1
compute_environments = [
aws_batch_compute_environment.batch_compute_env.arn
]
compute_environment_order {
order = 1
compute_environment = aws_batch_compute_environment.batch_compute_env.arn
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

╷
│ Error: Unsupported argument
│ 
│   on main.tf line 257, in resource "aws_batch_compute_environment" "batch_compute_env":
│  257:   compute_environment_name = "BatchComputeEnvironment-${random_string.random.result}"
│ 
│ An argument named "compute_environment_name" is not expected here.
╵
╷
│ Error: Unsupported argument
│ 
│   on main.tf line 286, in resource "aws_batch_job_queue" "batch_job_queue":
│  286:   compute_environments = [
│ 
│ An argument named "compute_environments" is not expected here.
╵

}

resource "aws_iam_role" "sfn_batch_job_role" {
Expand Down