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(ec2/ecs): cacheInContext properties for machine images #16021

Merged
merged 7 commits into from
Sep 9, 2021

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Aug 12, 2021

Most MachineImage implementations look up AMIs from SSM Parameters,
and by default they will all look up the Parameters on each deployment.

This leads to instance replacement. Since we already know the SSM
Parameter Name and CDK already has a cached SSM context lookup, it
should be simple to get a stable AMI ID. This is not ideal because the
AMI will grow outdated over time, but users should have the option to
pick non-updating images in a convenient way.

Fixes #12484.


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

Most `MachineImage` implementations look up AMIs from SSM Parameters,
and by default they will all look up the Parameters on each deployment.

This leads to instance replacement. Since we already know the SSM
Parameter Name and CDK already has a cached SSM context lookup, it
should be simple to get a stable AMI ID. This is not ideal because the
AMI will grow outdated over time, but users should have the option to
pick non-updating images in a convenient way.

Fixes #12484.
@rix0rrr rix0rrr requested a review from a team August 12, 2021 15:50
@rix0rrr rix0rrr self-assigned this Aug 12, 2021
@gitpod-io
Copy link

gitpod-io bot commented Aug 12, 2021

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Aug 12, 2021

I'm not married to the property name, welcoming suggestions for improvement.

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 12, 2021
rix0rrr added a commit that referenced this pull request Aug 13, 2021
Previously, 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.
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*
packages/@aws-cdk/aws-ecs/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ecs/README.md Show resolved Hide resolved
packages/@aws-cdk/aws-ec2/lib/machine-image.ts Outdated Show resolved Hide resolved
*
* @default false
*/
readonly cachedInContext?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think just "cache" would be fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want people thinking about "context" though...

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, this feels like an implementation detail that doesn't need to be surfaced in the API name. All the customer cares is that the AMI does not change automatically without cache eviction

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you in general. What concerns me is that users might not know where to look for said cache eviction--which is why I want that word in there.

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*
@rix0rrr rix0rrr requested review from BenChaimberg and a team September 7, 2021 12:47
@BenChaimberg BenChaimberg added the pr/do-not-merge This PR should not be merged at this time. label Sep 7, 2021
Copy link
Contributor

@BenChaimberg BenChaimberg left a comment

Choose a reason for hiding this comment

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

See comment, feel free to merge if you disagree

*
* @default false
*/
readonly cachedInContext?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, this feels like an implementation detail that doesn't need to be surfaced in the API name. All the customer cares is that the AMI does not change automatically without cache eviction

@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Sep 9, 2021
@mergify
Copy link
Contributor

mergify bot commented Sep 9, 2021

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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: f389a79
  • Result: FAILED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 430f50a into master Sep 9, 2021
@mergify mergify bot deleted the huijbers/ecs-updating-ami branch September 9, 2021 12:59
@mergify
Copy link
Contributor

mergify bot commented Sep 9, 2021

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-autoscaling): machine ami id not caching to cdk.context.json
3 participants