Skip to content

Commit 0bac8a5

Browse files
authored
feat(ecs): add Amazon Linux 2023 to EcsOptimizedImage (#26989)
Add support for selecting Amazon Linux 2023 ECS Optimized images. Reference: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/retrieve-ecs-optimized_AMI.html Closes #26988. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7161005 commit 0bac8a5

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Diff for: packages/aws-cdk-lib/aws-ecs/lib/amis.ts

+15
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export class EcsOptimizedAmi implements ec2.IMachineImage {
139139
+ (this.windowsVersion ? 'ami-windows-latest/' : 'ecs/optimized-ami/')
140140
+ (this.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX ? 'amazon-linux/' : '')
141141
+ (this.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 ? 'amazon-linux-2/' : '')
142+
+ (this.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023 ? 'amazon-linux-2023/' : '')
142143
+ (this.windowsVersion ? `Windows_Server-${this.windowsVersion}-English-Full-ECS_Optimized/` : '')
143144
+ (this.hwType === AmiHardwareType.GPU ? 'gpu/' : '')
144145
+ (this.hwType === AmiHardwareType.ARM ? 'arm64/' : '')
@@ -192,6 +193,19 @@ export interface EcsOptimizedImageOptions {
192193
* Construct a Linux or Windows machine image from the latest ECS Optimized AMI published in SSM
193194
*/
194195
export class EcsOptimizedImage implements ec2.IMachineImage {
196+
/**
197+
* Construct an Amazon Linux 2023 image from the latest ECS Optimized AMI published in SSM
198+
*
199+
* @param hardwareType ECS-optimized AMI variant to use
200+
*/
201+
public static amazonLinux2023(hardwareType = AmiHardwareType.STANDARD, options: EcsOptimizedImageOptions = {}): EcsOptimizedImage {
202+
return new EcsOptimizedImage({
203+
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023,
204+
hardwareType,
205+
cachedInContext: options.cachedInContext,
206+
});
207+
}
208+
195209
/**
196210
* Construct an Amazon Linux 2 image from the latest ECS Optimized AMI published in SSM
197211
*
@@ -253,6 +267,7 @@ export class EcsOptimizedImage implements ec2.IMachineImage {
253267
+ (this.windowsVersion ? 'ami-windows-latest/' : 'ecs/optimized-ami/')
254268
+ (this.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX ? 'amazon-linux/' : '')
255269
+ (this.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 ? 'amazon-linux-2/' : '')
270+
+ (this.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023 ? 'amazon-linux-2023/' : '')
256271
+ (this.windowsVersion ? `Windows_Server-${this.windowsVersion}-English-Full-ECS_Optimized/` : '')
257272
+ (this.hwType === AmiHardwareType.GPU ? 'gpu/' : '')
258273
+ (this.hwType === AmiHardwareType.ARM ? 'arm64/' : '')

Diff for: packages/aws-cdk-lib/aws-ecs/test/cluster.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,17 @@ describe('cluster', () => {
982982

983983
});
984984

985+
testDeprecated('allows returning the correct image for linux 2023 for EcsOptimizedAmi', () => {
986+
// GIVEN
987+
const stack = new cdk.Stack();
988+
const ami = new ecs.EcsOptimizedAmi({
989+
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023,
990+
});
991+
992+
expect(ami.getImage(stack).osType).toEqual(ec2.OperatingSystemType.LINUX);
993+
994+
});
995+
985996
test('allows returning the correct image for linux for EcsOptimizedImage', () => {
986997
// GIVEN
987998
const stack = new cdk.Stack();
@@ -1009,6 +1020,24 @@ describe('cluster', () => {
10091020

10101021
});
10111022

1023+
test('allows returning the correct image for linux 2023 for EcsOptimizedImage', () => {
1024+
// GIVEN
1025+
const stack = new cdk.Stack();
1026+
1027+
expect(ecs.EcsOptimizedImage.amazonLinux2023().getImage(stack).osType).toEqual(
1028+
ec2.OperatingSystemType.LINUX);
1029+
1030+
});
1031+
1032+
test('allows returning the correct image for linux 2023 for EcsOptimizedImage with ARM hardware', () => {
1033+
// GIVEN
1034+
const stack = new cdk.Stack();
1035+
1036+
expect(ecs.EcsOptimizedImage.amazonLinux2023(ecs.AmiHardwareType.ARM).getImage(stack).osType).toEqual(
1037+
ec2.OperatingSystemType.LINUX);
1038+
1039+
});
1040+
10121041
test('allows returning the correct image for windows for EcsOptimizedImage', () => {
10131042
// GIVEN
10141043
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)