From a0ccdc5cd64be46635d9214c80a4a0fbcbd4f879 Mon Sep 17 00:00:00 2001 From: Seblat5ch Date: Fri, 3 May 2019 15:16:03 +0100 Subject: [PATCH 1/2] optimized CFN template removed mappings and added SSM Parameter as this will dynamically allow for the latest ecs-optimized-ami each time. - /aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id - /aws/service/ecs/optimized-ami/amazon-linux-2/arm64/recommended/image_id - /aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id - /aws/service/ecs/optimized-ami/amazon-linux/recommended/image_id Note: Your user account must have the following IAM permissions to retrieve the Amazon ECS-optimized AMI metadata. These permissions have been added to the AmazonECS_FullAccess IAM policy. ssm:GetParameters ssm:GetParameter ssm:GetParametersByPath --- templates/ecs-cluster.yaml | 46 +++++++++----------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/templates/ecs-cluster.yaml b/templates/ecs-cluster.yaml index a371e29..5680145 100644 --- a/templates/ecs-cluster.yaml +++ b/templates/ecs-cluster.yaml @@ -27,45 +27,19 @@ Parameters: VpcId: Type: AWS::EC2::VPC::Id + ECSOptimizedImage: + Description: ECS-Optimized AMI ID + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ecs/optimized-ami/amazon-linux/recommended/image_id + AllowedValues: + - /aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id + - /aws/service/ecs/optimized-ami/amazon-linux-2/arm64/recommended/image_id + - /aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id + - /aws/service/ecs/optimized-ami/amazon-linux/recommended/image_id Conditions: EC2: !Equals [ !Ref LaunchType, "EC2" ] - -Mappings: - AWSRegionToAMI: - ap-south-1: - AMI: ami-00491f6f - eu-west-3: - AMI: ami-9aef59e7 - eu-west-2: - AMI: ami-67cbd003 - eu-west-1: - AMI: ami-1d46df64 - ap-northeast-2: - AMI: ami-c212b2ac - ap-northeast-1: - AMI: ami-872c4ae1 - sa-east-1: - AMI: ami-af521fc3 - ca-central-1: - AMI: ami-435bde27 - ap-southeast-1: - AMI: ami-910d72ed - ap-southeast-2: - AMI: ami-58bb443a - eu-central-1: - AMI: ami-509a053f - us-east-1: - AMI: ami-28456852 - us-east-2: - AMI: ami-ce1c36ab - us-west-1: - AMI: ami-74262414 - us-west-2: - AMI: ami-decc7fa6 - - Resources: ECSRole: Type: AWS::IAM::Role @@ -160,7 +134,7 @@ Resources: - /etc/cfn/cfn-hup.conf - /etc/cfn/hooks.d/cfn-auto-reloader.conf Properties: - ImageId: !FindInMap [ AWSRegionToAMI, !Ref "AWS::Region", AMI ] + ImageId: !Ref ECSOptimizedImage InstanceType: !Ref InstanceType IamInstanceProfile: !Ref InstanceProfile SecurityGroups: From e962e3c1bb4a7ef1e9a469173b38bc5f60f54c72 Mon Sep 17 00:00:00 2001 From: Seblat5ch Date: Fri, 3 May 2019 15:18:04 +0100 Subject: [PATCH 2/2] No longer required see ecs cluster template --- bin/get_amis.sh | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100755 bin/get_amis.sh diff --git a/bin/get_amis.sh b/bin/get_amis.sh deleted file mode 100755 index ff0f817..0000000 --- a/bin/get_amis.sh +++ /dev/null @@ -1,13 +0,0 @@ -echo "AWSRegionToAMI:" - -for region in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text) -do - echo " ${region}:" - echo -n " AMI: " - - aws ec2 describe-images \ - --owners amazon \ - --query 'reverse(sort_by(Images[?Name != `null`] | [?contains(Name, `amazon-ecs-optimized`) == `true`], &CreationDate))[:1].ImageId' \ - --output text \ - --region $region -done