diff --git a/sfn-manage-batch-job-tf/README.md b/sfn-manage-batch-job-tf/README.md index f2b97a7a7c..88fce5e513 100644 --- a/sfn-manage-batch-job-tf/README.md +++ b/sfn-manage-batch-job-tf/README.md @@ -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 @@ -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) ## Deployment Instructions diff --git a/sfn-manage-batch-job-tf/main.tf b/sfn-manage-batch-job-tf/main.tf index 3a2ae45982..cdd843f790 100644 --- a/sfn-manage-batch-job-tf/main.tf +++ b/sfn-manage-batch-job-tf/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = "~>4.0" + version = "~> 6.0" } } } @@ -218,7 +218,11 @@ resource "aws_iam_role" "batch_role" { }, ] }) - managed_policy_arns = ["arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"] +} + +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 @@ -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 @@ -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 { @@ -264,10 +272,10 @@ 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 ] } @@ -275,9 +283,10 @@ 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 + } } resource "aws_iam_role" "sfn_batch_job_role" {