Closed patlougheed closed 11 months ago
Hi @patlougheed , thanks for reaching out. I tried to reproduce the error with this updated code -
asg = autoscaling.AutoScalingGroup(
self, "DefaultAutoScalingGroup",
instance_type=ec2.InstanceType("t2.micro"),
machine_image=ecs.EcsOptimizedImage.amazon_linux2(),
vpc=vpc,
require_imdsv2= True,
)
I can confirm the error. Here is a similiar non-responsive issue created in the past as well. Marking this as P1.
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Hi folks - this problem appears to also exist when using A LaunchTemplate with a MixedInstancesPolicy and RequireImdsv2=true
Going to see if I can get a PR on the go for the above issue
I also get the above error, but was able to solve it by setting RequireImdsv2
only on the launch template, but not on the auto scaling group itself.
Maybe the RequireImdsv2
property should just receive a few changes in packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts
, like
SecurityGroup
, Role
, etc.) have, saying * 'launchTemplate' and 'mixedInstancesPolicy' must not be specified when this property is specified
verifyNoLaunchConfigPropIsGiven()
method to give a more meaningful error message on synth
Describe the bug
When configuring an AutoScalingGroup with
requireImdsv2
set to true and thegenerateLaunchTemplateInsteadOfLaunchConfig
context flag set to true,cdk synth
throws an error:Expected Behavior
No error; launch template should have
LaunchTemplateData.MetadataOptions.HttpTokens
set to "required" in resulting CloudFormation output.Current Behavior
cdk synth
yields:Reproduction Steps
In stack.py:
In cdk.json:
Then run
cdk synth
.Possible Solution
aws-autoscaling/lib/aspects/require-imdsv2-aspect.ts appears to target
LaunchConfiguration
s only, notLaunchTemplate
s.It similar aspect in (aws-ec2)[https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-ec2/lib/aspects/require-imdsv2-aspect.ts] has similar code that appears to support
LaunchTemplate
s.Additional Information/Context
No response
CDK CLI Version
2.101.1
Framework Version
2.101.1
Node.js Version
v20.7.0
OS
MacOS 14
Language
Python
Language Version
Python 3.10.9
Other information
No response