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

fix(ec2): AmazonLinuxImage construct generates incorrect SSM parameter name for AL2023 images #27698

Merged
merged 7 commits into from
Nov 10, 2023

Conversation

tam0ri
Copy link
Contributor

@tam0ri tam0ri commented Oct 26, 2023

AmazonLinuxImage construct generates SSM parameter name for Amazon Linux images. The naming convention for Amazon Linux 2023 images is a bit different from Amazon Linux 2. For example, virtualization type (e.g. HVM) or backend storage type (e.g. GP2) are not included in parameter's name for AL2023.

AL2:

* "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs",
* "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2",
* "/aws/service/ami-amazon-linux-latest/amzn2-ami-kernel-5.10-hvm-x86_64-ebs",
* "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-arm64-gp2",
* "/aws/service/ami-amazon-linux-latest/amzn2-ami-minimal-hvm-arm64-ebs",
* "/aws/service/ami-amazon-linux-latest/amzn2-ami-kernel-5.10-hvm-arm64-gp2",
* "/aws/service/ami-amazon-linux-latest/amzn2-ami-kernel-5.10-hvm-x86_64-gp2",
* "/aws/service/ami-amazon-linux-latest/amzn2-ami-minimal-hvm-x86_64-ebs"

AL2023:

* "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-arm64",
* "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64",
* "/aws/service/ami-amazon-linux-latest/al2023-ami-minimal-kernel-6.1-arm64",
* "/aws/service/ami-amazon-linux-latest/al2023-ami-minimal-kernel-6.1-x86_64",
* "/aws/service/ami-amazon-linux-latest/al2023-ami-minimal-kernel-default-arm64",
* "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64",
* "/aws/service/ami-amazon-linux-latest/al2023-ami-minimal-kernel-default-x86_64",
* "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-arm64",

Currently, AmazonLinuxImage construct generates incorrect SSM parameter name for AL2023 images, which includes virtualization and storage type in the name. This causes validation error against non-existing parameter name. This PR solves the issue by avoiding to include virtualization and storage in parameter's name when AMAZON_LINUX_2023 is specified as generation.

Closes #27638


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

@aws-cdk-automation aws-cdk-automation requested a review from a team October 26, 2023 17:09
@github-actions github-actions bot added bug This issue is a bug. p1 admired-contributor [Pilot] contributed between 13-24 PRs to the CDK labels Oct 26, 2023
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Oct 26, 2023
@vinayak-kukreja vinayak-kukreja self-assigned this Nov 8, 2023
@vinayak-kukreja vinayak-kukreja changed the title fix(ec2): AmazonLinuxImage construct generates incorrect SSM parameter name for AL2023 images fix(ec2): AmazonLinuxImage construct generates incorrect SSM parameter name for AL2023 images Nov 8, 2023
Signed-off-by: Vinayak Kukreja <vinakuk@amazon.com>
@vinayak-kukreja vinayak-kukreja added the pr/do-not-merge This PR should not be merged at this time. label Nov 8, 2023
vinayak-kukreja
vinayak-kukreja previously approved these changes Nov 8, 2023
@vinayak-kukreja
Copy link
Contributor

Hey, thank you for your contribution. I made some updates to the integ test to get it working. Since I have added code, I have asked someone else to add a review too. But it looks good to me.

Comment on lines +420 to +435
test('throw error if storage param is set for Amazon Linux 2023', () => {
expect(() => {
new ec2.AmazonLinuxImage({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023,
storage: ec2.AmazonLinuxStorage.GENERAL_PURPOSE,
}).getImage(stack);
}).toThrow(/Storage parameter does not exist in SSM parameter name for Amazon Linux 2023./);
});

test('throw error if virtualization param is set for Amazon Linux 2023', () => {
expect(() => {
new ec2.AmazonLinuxImage({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023,
virtualization: ec2.AmazonLinuxVirt.HVM,
}).getImage(stack);
}).toThrow(/Virtualization parameter does not exist in SSM parameter name for Amazon Linux 2023./);
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests are outside of the describe block. Is that intended? It looks like theres a mix of 2022 and 2023 tests in the latest describe block. Is that intended too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@scanlonp Thank you for your comment!

These tests are outside of the describe block. Is that intended?

Yes, this is intentional. I added three tests.

  1. 'AmazonLinuxImage with AMAZON_LINUX_2023'
  2. 'throw error if storage param is set for Amazon Linux 2023'
  3. 'throw error if virtualization param is set for Amazon Linux 2023'

1 is located in latest describe block. This is because I want to verify whether AmazonLinuxImage construct generates SSM parameter path for the latest AL2023 image by this change. 2 and 3 are not located in the describe block. This is also intentional because these tests are similar with the following tests located outside of the describe block.

test('throw error if storage param is set for Amazon Linux 2022', () => {
expect(() => {
ec2.MachineImage.latestAmazonLinux({
cachedInContext: true,
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2022,
storage: ec2.AmazonLinuxStorage.GENERAL_PURPOSE,
}).getImage(stack).imageId;
}).toThrow(/Storage parameter does not exist in smm parameter name for Amazon Linux 2022./);
});
test('throw error if virtualization param is set for Amazon Linux 2022', () => {
expect(() => {
ec2.MachineImage.latestAmazonLinux({
cachedInContext: true,
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2022,
virtualization: ec2.AmazonLinuxVirt.HVM,
}).getImage(stack).imageId;
}).toThrow(/Virtualization parameter does not exist in smm parameter name for Amazon Linux 2022./);
});

If I should move 2 and 3 into directly below the above tests, please let me know.

It looks like theres a mix of 2022 and 2023 tests in the latest describe block. Is that intended too?

This is not my intention. Before I added these tests, tests for both 2022 and 2023 are located in the describe block as below.
https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts#L300-L407

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 8, 2023
scanlonp
scanlonp previously approved these changes Nov 10, 2023
Copy link
Contributor

@scanlonp scanlonp left a comment

Choose a reason for hiding this comment

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

Thanks for your explanation. I think the formatting of the tests is fine if it was your intention. We can reorganize as necessary in the future, but it is likely ok, and certainly should not block this PR.

@mergify mergify bot dismissed stale reviews from vinayak-kukreja and scanlonp November 10, 2023 07:09

Pull request has been modified.

Copy link
Contributor

@scanlonp scanlonp left a comment

Choose a reason for hiding this comment

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

See above.

@vinayak-kukreja
Copy link
Contributor

@Mergifyio update

Copy link
Contributor

mergify bot commented Nov 10, 2023

update

✅ Branch has been successfully updated

@vinayak-kukreja vinayak-kukreja removed the pr/do-not-merge This PR should not be merged at this time. label Nov 10, 2023
Copy link
Contributor

mergify bot commented Nov 10, 2023

Thank you for contributing! Your pull request will be updated from main 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: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: b2d932b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit f6c1e62 into aws:main Nov 10, 2023
9 checks passed
Copy link
Contributor

mergify bot commented Nov 10, 2023

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

mikewrighton pushed a commit that referenced this pull request Nov 13, 2023
…ter name for AL2023 images (#27698)

AmazonLinuxImage construct generates SSM parameter name for Amazon Linux images. The naming convention for Amazon Linux 2023 images is a bit different from Amazon Linux 2. For example, virtualization type (e.g. HVM) or backend storage type (e.g. GP2) are not included in parameter's name for AL2023. 

AL2:
https://github.com/aws/aws-cdk/blob/d0d75478e1cf3bb9a06f33642b9a06fc68d0c99d/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux2.ts#L77-L84

AL2023:
https://github.com/aws/aws-cdk/blob/d0d75478e1cf3bb9a06f33642b9a06fc68d0c99d/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2023.ts#L59-L66


Currently, AmazonLinuxImage construct generates incorrect SSM parameter name for AL2023 images, which includes virtualization and storage type in the name. This causes validation error against non-existing parameter name. This PR solves the issue by avoiding to include virtualization and storage in parameter's name when AMAZON_LINUX_2023 is specified as generation.

Closes #27638

----

*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
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK bug This issue is a bug. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ec2: Fetches Incorrect gp2 Volume Type for AL2023 AmazonLinuxImage
4 participants