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): add support Amazon Linux 2 #1484

Merged
merged 2 commits into from
Jan 6, 2019
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
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc,
instanceType: new ec2.InstanceType('t2.xlarge'),
machineImage: new EcsOptimizedAmi(),
// Or use ECS-Optimized Amazon Linux 2 AMI
// machineImage: new EcsOptimizedAmi({ generation: ec2.AmazonLinuxGeneration.AmazonLinux2 }),
desiredCapacity: 3,
// ... other options here ...
});
Expand Down
25 changes: 22 additions & 3 deletions packages/@aws-cdk/aws-ecs/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,37 @@ export class Cluster extends cdk.Construct implements ICluster {
}
}

export interface EcsOptimizedAmiProps {
/**
* What generation of Amazon Linux to use
*
* @default AmazonLinux
*/
generation?: ec2.AmazonLinuxGeneration;
}

/**
* Construct a Linux machine image from the latest ECS Optimized AMI published in SSM
*/
export class EcsOptimizedAmi implements ec2.IMachineImageSource {
private static AmiParameterName = "/aws/service/ecs/optimized-ami/amazon-linux/recommended";
export class EcsOptimizedAmi implements ec2.IMachineImageSource {
private readonly generation: ec2.AmazonLinuxGeneration;
private readonly amiParameterName: string;

constructor(props?: EcsOptimizedAmiProps) {
this.generation = (props && props.generation) || ec2.AmazonLinuxGeneration.AmazonLinux;
if (this.generation === ec2.AmazonLinuxGeneration.AmazonLinux2) {
this.amiParameterName = "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended";
} else {
this.amiParameterName = "/aws/service/ecs/optimized-ami/amazon-linux/recommended";
}
}

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

const json = ssmProvider.parameterValue("{\"image_id\": \"\"}");
Expand Down