core: CloudFormation-Validate::W9010
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 74
Description
### Describe the bug
Doing this in CDK (Python):
```
aws_ec2.Instance(
...
machine_image=aws_ec2.MachineImage.generic_linux(ami_map={Stack.of(self).region: aws_ec2.LookupMachineImage(name=ami_name).get_image(self).image_id)}
```
Generates the following CFN:
```
MyInstance:
Type: AWS::EC2::Instance
Properties:
...
ImageId: ami-######
'''
Running `cdk synth` generates the following warning:
```
WARNING ImageId: Hardcoded AMI ID - use a parameter or mapping for portability (CloudFormation Validate)
test-emc-cdk-lib/EmcEc21/Resource (EmcEc21FC170D30) aws-cdk-lib.aws_ec2.CfnInstance
Acknowledge with 'CloudFormation-Validate::W9010'
```
In CDK determining values via the code as opposed to via a map is common practice and should not throw warnings.
I believe this issue was introduced in this change - https://github.com/aws/aws-cdk/pull/38135.
A potential fix would be to add this to error code here - https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/core/lib/validation/cloudformation-validate-plugin.ts#L182.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Library Version
_No response_
### Expected Behavior
I expect the synth to complete without warnings.
### Current Behavior
Running `cdk synth` generates the following warning:
```
WARNING ImageId: Hardcoded AMI ID - use a parameter or mapping for portability (CloudFormation Validate)
test-emc-cdk-lib/EmcEc21/Resource (EmcEc21FC170D30) aws-cdk-lib.aws_ec2.CfnInstance
Acknowledge with 'CloudFormation-Validate::W9010'
```
### Reproduction Steps
In description
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### AWS CDK Library version (aws-cdk-lib)
v2.262.0
### AWS CDK CLI version
2.1132.1
### Node.js Version
v24.18.0
### OS
Windows
### Language
Python
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start in packages/aws-cdk-lib/core/lib/validation/cloudformation-validate-plugin.ts at the W9010 handling referenced in the issue, then reproduce the Python CDK example with cdk synth. Verify that an AMI ID resolved through CDK code no longer produces the CloudFormation-Validate::W9010 warning while genuinely hardcoded IDs retain the validation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python, typescript
- Domain
- cloud, devops, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 66/100