-
Notifications
You must be signed in to change notification settings - Fork 4k
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
ec2: Fetches Incorrect gp2 Volume Type for AL2023 AmazonLinuxImage #27638
Comments
@DharmSonariya I wasn't able to reproduce. Can you confirm the output of |
@msambol Thank you for looking into this. Here's the output of the cdk version command from my setup: |
@DharmSonariya what does your |
Hi @msambol,
|
Hi @msambol, In the aws-cdk/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts file, I couldn't find a value for gp3 under the AmazonLinuxStorage enum:
The enum looks like this: export enum AmazonLinuxStorage {
/**
* EBS-backed storage
*/
EBS = 'ebs',
/**
* S3-backed storage
*/
S3 = 's3',
/**
* General Purpose-based storage (recommended)
*/
GENERAL_PURPOSE = 'gp2',
} Given the documentation mentions that AL2023 AMIs use Amazon EBS gp3 volumes by default, this could potentially be the root of the issue. Hope this clue helps in resolving the bug. Let me know if you need any more details or if I can assist further. |
I could reproduce it on my end with the following simple sample code. import * as cdk from 'aws-cdk-lib';
import {aws_ec2 as ec2} from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class Issue27638Stack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = ec2.Vpc.fromLookup(this, 'VPC', {
vpcId: "<my vpc id>"
});
new ec2.Instance(this, 'targetInstance', {
vpc: vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023 }),
});
}
} In AmazonLinuxImage construct's implementation, AMAZON_LINUX_2023 is not handled to be aligned with SSM parameter's naming conventions. aws-cdk/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts Lines 486 to 497 in 2abc59a
This leads incorrect parameter name for AMAZON_LINUX_2023. We should add the same logic as AMAZON_LINUX_2022. I'll submit PR later. In the meantime, using latestAmazonLinux2023 method as below is workaround. This method generates correct parameter name. new ec2.Instance(this, 'targetInstance', {
vpc: vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
machineImage: ec2.MachineImage.latestAmazonLinux2023(),
}); |
Hi @tam0ri, Thank you so much for taking the time to reproduce the issue and for pinpointing the cause. I really appreciate your thorough analysis. It's great to hear that a PR will be submitted to address this. I'll definitely try out the latestAmazonLinux2023 method as a temporary workaround. Thanks for suggesting it. |
…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*
|
…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*
Describe the bug
I encountered a validation error when trying to use the ec2.AmazonLinuxImage with AmazonLinuxGeneration.AMAZON_LINUX_2023. It seems the CDK is attempting to fetch an AMI that uses the gp2 volume type for AL2023.
AWS documentation also confirms that AL2023 uses the gp3 volume type by default: link to AWS docs.
There is no AMI al2023-ami with gp2.
aws ssm get-parameters-by-path --path /aws/service/ami-amazon-linux-latest --query "Parameters[].Name"
Expected Behavior
The CDK should be able to fetch the correct AMI for AmazonLinuxGeneration.AMAZON_LINUX_2023.
Current Behavior
Received a ValidationError as follows:
❌ Deployment failed: Error [ValidationError]: Unable to fetch parameters [/aws/service/ami-amazon-linux-latest/al2023-ami-hvm-x86_64-gp2] from parameter store for this account.
Reproduction Steps
ec2.AmazonLinuxImage(
generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023,
edition=ec2.AmazonLinuxEdition.STANDARD,
)
Possible Solution
This issue seems similar to a previously resolved bug: #26274 by @pahud
Additional Information/Context
No response
CDK CLI Version
2.102.0 (build 2abc59a)
Framework Version
No response
Node.js Version
v18.18.2
OS
Linux 6.2.0-34-generic #34 x86_64 GNU/Linux
Language
Python
Language Version
Python 3.11.6
Other information
No response
The text was updated successfully, but these errors were encountered: