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 support for Bottlerocket on ARM64 #15454

Merged
merged 2 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions packages/@aws-cdk/aws-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ If you omit the property `vpc`, the construct will create a new VPC with two AZs
[Bottlerocket](https://aws.amazon.com/bottlerocket/) is a Linux-based open source operating system that is
purpose-built by AWS for running containers. You can launch Amazon ECS container instances with the Bottlerocket AMI.

> **NOTICE**: The Bottlerocket AMI is in developer preview release for Amazon ECS and is subject to change.

The following example will create a capacity with self-managed Amazon EC2 capacity of 2 `c5.large` Linux instances running with `Bottlerocket` AMI.

The following example adds Bottlerocket capacity to the cluster:
Expand All @@ -164,7 +162,16 @@ cluster.addCapacity('graviton-cluster', {
instanceType: new ec2.InstanceType('c6g.large'),
machineImage: ecs.EcsOptimizedImage.amazonLinux2(ecs.AmiHardwareType.ARM),
});
```

Bottlerocket is also supported:

```ts
cluster.addCapacity('graviton-cluster', {
minCapacity: 2,
instanceType: new ec2.InstanceType('c6g.large'),
machineImage: ecs.MachineImageType.BOTTLEROCKET,
});
```

### Spot Instances
Expand Down
19 changes: 17 additions & 2 deletions packages/@aws-cdk/aws-ecs/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ export class Cluster extends Resource implements ICluster {
// Do 2-way defaulting here: if the machineImageType is BOTTLEROCKET, pick the right AMI.
// Otherwise, determine the machineImageType from the given AMI.
const machineImage = options.machineImage ??
(options.machineImageType === MachineImageType.BOTTLEROCKET ? new BottleRocketImage() : new EcsOptimizedAmi());
(options.machineImageType === MachineImageType.BOTTLEROCKET ? new BottleRocketImage({
architecture: options.instanceType.architecture,
}) : new EcsOptimizedAmi());

const machineImageType = options.machineImageType ??
(isBottleRocketImage(machineImage) ? MachineImageType.BOTTLEROCKET : MachineImageType.AMAZON_LINUX_2);
Expand Down Expand Up @@ -767,6 +769,13 @@ export interface BottleRocketImageProps {
* @default - BottlerocketEcsVariant.AWS_ECS_1
*/
readonly variant?: BottlerocketEcsVariant;

/**
* The CPU architecture
*
* @default - x86_64
*/
readonly architecture?: ec2.InstanceArchitecture;
}

/**
Expand All @@ -779,14 +788,20 @@ export class BottleRocketImage implements ec2.IMachineImage {
*/
private readonly variant: string;

/**
* Instance architecture
*/
private readonly architecture: ec2.InstanceArchitecture;

/**
* Constructs a new instance of the BottleRocketImage class.
*/
public constructor(props: BottleRocketImageProps = {}) {
this.variant = props.variant ?? BottlerocketEcsVariant.AWS_ECS_1;
this.architecture = props.architecture ?? ec2.InstanceArchitecture.X86_64;

// set the SSM parameter name
this.amiParameterName = `/aws/service/bottlerocket/${this.variant}/x86_64/latest/image_id`;
this.amiParameterName = `/aws/service/bottlerocket/${this.variant}/${this.architecture}/latest/image_id`;
}

/**
Expand Down
31 changes: 30 additions & 1 deletion packages/@aws-cdk/aws-ecs/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,36 @@ nodeunitShim({
test.done();
},

'cluster capacity with bottlerocket AMI, by setting the machineImage'(test: Test) {
'correct bottlerocket AMI for ARM64 architecture'(test: Test) {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'test');

const cluster = new ecs.Cluster(stack, 'EcsCluster');
cluster.addCapacity('bottlerocket-asg', {
instanceType: new ec2.InstanceType('m6g.large'),
machineImageType: ecs.MachineImageType.BOTTLEROCKET,
});

// THEN
expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', {
ImageId: {
Ref: 'SsmParameterValueawsservicebottlerocketawsecs1arm64latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter',
},
}));

const assembly = app.synth();
const template = assembly.getStackByName(stack.stackName).template;
test.deepEqual(template.Parameters, {
SsmParameterValueawsservicebottlerocketawsecs1arm64latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter: {
Type: 'AWS::SSM::Parameter::Value<String>',
Default: '/aws/service/bottlerocket/aws-ecs-1/arm64/latest/image_id',
},
});
test.done();
},

'throws when machineImage and machineImageType both specified'(test: Test) {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'test');
Expand Down
Loading