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(aws-ecs): include GPU & ARM based ECS optimized AMI options #2453

Merged
merged 14 commits into from
May 23, 2019
Merged
Changes from 2 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
51 changes: 50 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class Cluster extends Resource implements ICluster {
const autoScalingGroup = new autoscaling.AutoScalingGroup(this, id, {
...options,
vpc: this.vpc,
machineImage: new EcsOptimizedAmi(),
machineImage: options.machineImage || new EcsOptimizedAmi(),
updateType: options.updateType || autoscaling.UpdateType.ReplacingUpdate,
instanceType: options.instanceType,
});
Expand Down Expand Up @@ -265,6 +265,48 @@ export class EcsOptimizedAmi implements ec2.IMachineImageSource {
}
}

/**
* Construct a GPU-based Linux machine image from the latest ECS Optimized AMI published in SSM
*/
export class EcsGpuOptimizedAmi implements ec2.IMachineImageSource {
mattmcclean marked this conversation as resolved.
Show resolved Hide resolved
private readonly amiParameterName: string = '/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended';

/**
* Return the correct image
*/
public getImage(scope: Construct): ec2.MachineImage {
const ssmProvider = new SSMParameterProvider(scope, {
parameterName: this.amiParameterName
});

const json = ssmProvider.parameterValue("{\"image_id\": \"\"}");
const ami = JSON.parse(json).image_id;

return new ec2.MachineImage(ami, new ec2.LinuxOS());
}
}

/**
* Construct a ARM-based Linux machine image from the latest ECS Optimized AMI published in SSM
*/
export class EcsArmOptimizedAmi implements ec2.IMachineImageSource {
private readonly amiParameterName: string = '/aws/service/ecs/optimized-ami/amazon-linux-2/arm64/recommended';

/**
* Return the correct image
*/
public getImage(scope: Construct): ec2.MachineImage {
const ssmProvider = new SSMParameterProvider(scope, {
parameterName: this.amiParameterName
});

const json = ssmProvider.parameterValue("{\"image_id\": \"\"}");
const ami = JSON.parse(json).image_id;

return new ec2.MachineImage(ami, new ec2.LinuxOS());
}
}

/**
* An ECS cluster
*/
Expand Down Expand Up @@ -432,6 +474,13 @@ export interface AddAutoScalingGroupCapacityOptions {
* @default 300
*/
readonly taskDrainTimeSeconds?: number;

/**
* The machine image for the ECS instances
*
* @default - No default machine image
mattmcclean marked this conversation as resolved.
Show resolved Hide resolved
*/
readonly machineImage?: ec2.IMachineImageSource;
}

/**
Expand Down