diff --git a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts index 7069cf43644c5..d22694318f1f9 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts @@ -31,6 +31,7 @@ export enum AmiHardwareType { * ECS-optimized Windows version list */ export enum WindowsOptimizedVersion { + SERVER_2022 = '2022', SERVER_2019 = '2019', SERVER_2016 = '2016', } @@ -134,13 +135,14 @@ export class EcsOptimizedAmi implements ec2.IMachineImage { } // set the SSM parameter name - this.amiParameterName = '/aws/service/ecs/optimized-ami/' + this.amiParameterName = '/aws/service/' + + (this.windowsVersion ? 'ami-windows-latest/' : 'ecs/optimized-ami/') + (this.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX ? 'amazon-linux/' : '') + (this.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 ? 'amazon-linux-2/' : '') - + (this.windowsVersion ? `windows_server/${this.windowsVersion}/english/full/` : '') + + (this.windowsVersion ? `windows_server/Windows_Server-${this.windowsVersion}-English-Full-ECS_Optimized/` : '') + (this.hwType === AmiHardwareType.GPU ? 'gpu/' : '') + (this.hwType === AmiHardwareType.ARM ? 'arm64/' : '') - + 'recommended/image_id'; + + (this.windowsVersion ? 'image_id' : 'recommended/image_id'); this.cachedInContext = props?.cachedInContext ?? false; } @@ -247,13 +249,14 @@ export class EcsOptimizedImage implements ec2.IMachineImage { } // set the SSM parameter name - this.amiParameterName = '/aws/service/ecs/optimized-ami/' + this.amiParameterName = '/aws/service/' + + (this.windowsVersion ? 'ami-windows-latest/' : 'ecs/optimized-ami/') + (this.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX ? 'amazon-linux/' : '') + (this.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 ? 'amazon-linux-2/' : '') - + (this.windowsVersion ? `windows_server/${this.windowsVersion}/english/full/` : '') + + (this.windowsVersion ? `windows_server/Windows_Server-${this.windowsVersion}-English-Full-ECS_Optimized/` : '') + (this.hwType === AmiHardwareType.GPU ? 'gpu/' : '') + (this.hwType === AmiHardwareType.ARM ? 'arm64/' : '') - + 'recommended/image_id'; + + (this.windowsVersion ? 'image_id' : 'recommended/image_id'); this.cachedInContext = props?.cachedInContext ?? false; } diff --git a/packages/aws-cdk-lib/aws-ecs/test/cluster.test.ts b/packages/aws-cdk-lib/aws-ecs/test/cluster.test.ts index 60af60677adfb..ace38982feff4 100644 --- a/packages/aws-cdk-lib/aws-ecs/test/cluster.test.ts +++ b/packages/aws-cdk-lib/aws-ecs/test/cluster.test.ts @@ -903,7 +903,7 @@ describe('cluster', () => { expect(template.Parameters).toEqual({ SsmParameterValueawsserviceecsoptimizedamiwindowsserver2019englishfullrecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter: { Type: 'AWS::SSM::Parameter::Value', - Default: '/aws/service/ecs/optimized-ami/windows_server/2019/english/full/recommended/image_id', + Default: '/aws/service/ami-windows-latest/Windows_Server-2019-English-Full-ECS_Optimized/image_id', }, }); @@ -1137,7 +1137,7 @@ describe('cluster', () => { expect(template.Parameters).toEqual({ SsmParameterValueawsserviceecsoptimizedamiwindowsserver2019englishfullrecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter: { Type: 'AWS::SSM::Parameter::Value', - Default: '/aws/service/ecs/optimized-ami/windows_server/2019/english/full/recommended/image_id', + Default: '/aws/service/ami-windows-latest/Windows_Server-2019-English-Full-ECS_Optimized/image_id', }, });