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): bottlerocket support #10097

Merged
merged 11 commits into from
Sep 2, 2020
Merged

feat(ecs): bottlerocket support #10097

merged 11 commits into from
Sep 2, 2020

Conversation

pahud
Copy link
Contributor

@pahud pahud commented Sep 1, 2020

feat(ecs): bottlerocket support

Closes: #10085

  • machineImageType to select the bottlerocket machine image type

  • SSM session manager enabled by default

  • update README

  • integ test

  • unit test


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@SomayaB SomayaB added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Sep 1, 2020
@iamhopaul123 iamhopaul123 self-assigned this Sep 1, 2020
Copy link
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Thank you so much for this quick PR after bottlerocket just published its ECS variant.

packages/@aws-cdk/aws-ecs/lib/cluster.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ecs/lib/cluster.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ecs/lib/cluster.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ecs/lib/cluster.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ecs/lib/cluster.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ecs/README.md Show resolved Hide resolved
@iamhopaul123 iamhopaul123 removed their assignment Sep 2, 2020
@pahud pahud marked this pull request as ready for review September 2, 2020 18:15
@pahud
Copy link
Contributor Author

pahud commented Sep 2, 2020

HI @iamhopaul123 ,

Should all addressed. Please take a look again. Thanks.

@pahud
Copy link
Contributor Author

pahud commented Sep 2, 2020

When I successfully run the integ test, I got 2 bottlerocket instances

圖片

And they both registered to the cluster with ACTIVE status

圖片

And I can hit the connect with the session manager to the instances

圖片

To enter the shell

圖片

@pahud
Copy link
Contributor Author

pahud commented Sep 2, 2020

If I extend the integ test to create the service like this

import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import * as ecs from '../../lib';
import * as patterns from '@aws-cdk/aws-ecs-patterns';

const app = new cdk.App();

const stack = new cdk.Stack(app, 'aws-ecs-integ-bottlerocket');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, natGateways: 1 });

const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });

cluster.addCapacity('bottlerocket-asg', {
  minCapacity: 2,
  instanceType: new ec2.InstanceType('c5.large'),
  machineImageType: ecs.MachineImageType.BOTTLEROCKET,
});

const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef');

const web = taskDefinition.addContainer('web', {
  image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
  memoryReservationMiB: 1024,
});

web.addPortMappings({
  containerPort: 80,
})

new patterns.ApplicationLoadBalancedEc2Service(stack, 'ALBService', {
  cluster,
  taskDefinition,
})

app.synth();

I got the service deployed with the ALB URL returned

圖片

And if I hit the URL, I got the sample PHP running as expected

圖片

I am not going to extend this in the integ.bottlerocket.ts, just in case anyone is just interested. :-)

Copy link
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it :shipit: Thank you for your contribution!

@mergify
Copy link
Contributor

mergify bot commented Sep 2, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: e4671aa
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Sep 2, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 088abec into aws:master Sep 2, 2020
@nathanpeck
Copy link
Member

Hey @pahud there are a couple issues / caveats that I think we might want to have checks for:

  • Bottlerocket doesn't support all instance families yet: "Bottlerocket builds from AWS are supported on an HVM and EC2 Bare Metal instance families with the exception of the P, G, F, and INF instance types."
  • Also Bottlerocket does not yet support AWSVPC network mode yet, so it might make sense to have a check for that

@pahud
Copy link
Contributor Author

pahud commented Sep 3, 2020

Thank you @nathanpeck

Let me fix this in another PR 😄

mergify bot pushed a commit that referenced this pull request Aug 13, 2021
As introduced in #10097, Bottlerocket had to be explicitly (and only) selected
via setting `machineImageType`, which would pick an appropriate
`machineImage`.

Setting `machineImage` to `new BottleRocketImage()` would not be
sufficient, since the feature also requires configuring additional
UserData commands which are only added if `machineImageType` was set.

This method of configuration does not allow customization of the AMI,
such as introduced in #16021.

Instead, we reverse the logic: `machineImageType` may still be necessary
to autoconfigure UserData if we can't know what the machineImage is
(for example in case of a preconfigured AutoScalingGroup), but otherwise
is derived from what `machineImage` is being used.

We allow configuring both fields at the same time for the case when the
autodetection fails.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
As introduced in aws#10097, Bottlerocket had to be explicitly (and only) selected
via setting `machineImageType`, which would pick an appropriate
`machineImage`.

Setting `machineImage` to `new BottleRocketImage()` would not be
sufficient, since the feature also requires configuring additional
UserData commands which are only added if `machineImageType` was set.

This method of configuration does not allow customization of the AMI,
such as introduced in aws#16021.

Instead, we reverse the logic: `machineImageType` may still be necessary
to autoconfigure UserData if we can't know what the machineImage is
(for example in case of a preconfigured AutoScalingGroup), but otherwise
is derived from what `machineImage` is being used.

We allow configuring both fields at the same time for the case when the
autodetection fails.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Sep 6, 2021
As introduced in aws#10097, Bottlerocket had to be explicitly (and only) selected
via setting `machineImageType`, which would pick an appropriate
`machineImage`.

Setting `machineImage` to `new BottleRocketImage()` would not be
sufficient, since the feature also requires configuring additional
UserData commands which are only added if `machineImageType` was set.

This method of configuration does not allow customization of the AMI,
such as introduced in aws#16021.

Instead, we reverse the logic: `machineImageType` may still be necessary
to autoconfigure UserData if we can't know what the machineImage is
(for example in case of a preconfigured AutoScalingGroup), but otherwise
is derived from what `machineImage` is being used.

We allow configuring both fields at the same time for the case when the
autodetection fails.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
david-doyle-as24 pushed a commit to david-doyle-as24/aws-cdk that referenced this pull request Sep 7, 2021
As introduced in aws#10097, Bottlerocket had to be explicitly (and only) selected
via setting `machineImageType`, which would pick an appropriate
`machineImage`.

Setting `machineImage` to `new BottleRocketImage()` would not be
sufficient, since the feature also requires configuring additional
UserData commands which are only added if `machineImageType` was set.

This method of configuration does not allow customization of the AMI,
such as introduced in aws#16021.

Instead, we reverse the logic: `machineImageType` may still be necessary
to autoconfigure UserData if we can't know what the machineImage is
(for example in case of a preconfigured AutoScalingGroup), but otherwise
is derived from what `machineImage` is being used.

We allow configuring both fields at the same time for the case when the
autodetection fails.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aws-ecs] Bottlerocket support for Amazon ECS
6 participants