Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ecs): add Amazon Linux 2023 to EcsOptimizedImage #26989

Merged
merged 5 commits into from
Sep 9, 2023
Merged
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
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/aws-ecs/lib/amis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class EcsOptimizedAmi implements ec2.IMachineImage {
+ (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.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023 ? 'amazon-linux-2023/' : '')
+ (this.windowsVersion ? `Windows_Server-${this.windowsVersion}-English-Full-ECS_Optimized/` : '')
+ (this.hwType === AmiHardwareType.GPU ? 'gpu/' : '')
+ (this.hwType === AmiHardwareType.ARM ? 'arm64/' : '')
Expand Down Expand Up @@ -192,6 +193,19 @@ export interface EcsOptimizedImageOptions {
* Construct a Linux or Windows machine image from the latest ECS Optimized AMI published in SSM
*/
export class EcsOptimizedImage implements ec2.IMachineImage {
/**
* Construct an Amazon Linux 2023 image from the latest ECS Optimized AMI published in SSM
*
* @param hardwareType ECS-optimized AMI variant to use
*/
public static amazonLinux2023(hardwareType = AmiHardwareType.STANDARD, options: EcsOptimizedImageOptions = {}): EcsOptimizedImage {
return new EcsOptimizedImage({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023,
hardwareType,
cachedInContext: options.cachedInContext,
});
}

/**
* Construct an Amazon Linux 2 image from the latest ECS Optimized AMI published in SSM
*
Expand Down Expand Up @@ -253,6 +267,7 @@ export class EcsOptimizedImage implements ec2.IMachineImage {
+ (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.generation === ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023 ? 'amazon-linux-2023/' : '')
+ (this.windowsVersion ? `Windows_Server-${this.windowsVersion}-English-Full-ECS_Optimized/` : '')
+ (this.hwType === AmiHardwareType.GPU ? 'gpu/' : '')
+ (this.hwType === AmiHardwareType.ARM ? 'arm64/' : '')
Expand Down
29 changes: 29 additions & 0 deletions packages/aws-cdk-lib/aws-ecs/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,17 @@ describe('cluster', () => {

});

testDeprecated('allows returning the correct image for linux 2023 for EcsOptimizedAmi', () => {
// GIVEN
const stack = new cdk.Stack();
const ami = new ecs.EcsOptimizedAmi({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023,
});

expect(ami.getImage(stack).osType).toEqual(ec2.OperatingSystemType.LINUX);

});

test('allows returning the correct image for linux for EcsOptimizedImage', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down Expand Up @@ -1009,6 +1020,24 @@ describe('cluster', () => {

});

test('allows returning the correct image for linux 2023 for EcsOptimizedImage', () => {
// GIVEN
const stack = new cdk.Stack();

expect(ecs.EcsOptimizedImage.amazonLinux2023().getImage(stack).osType).toEqual(
ec2.OperatingSystemType.LINUX);

});

test('allows returning the correct image for linux 2023 for EcsOptimizedImage with ARM hardware', () => {
// GIVEN
const stack = new cdk.Stack();

expect(ecs.EcsOptimizedImage.amazonLinux2023(ecs.AmiHardwareType.ARM).getImage(stack).osType).toEqual(
ec2.OperatingSystemType.LINUX);

});

test('allows returning the correct image for windows for EcsOptimizedImage', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down