aws-cdk
aws-cdk copied to clipboard
aws-ec2: Add support for MetadataOptions in LaunchTemplate
Describe the feature
Add MetadataOptions support to LaunchTemplate.
Use Case
Right now I have a Launch Template I would like to override the HopLimit to 2. I am using the L2 Construct since that makes a lot of things simple, but it lacks support for MetadataOptions
Proposed Solution
lt = ec2.LaunchTemplate(
stack, lt_name,
instance_type=instance,
security_group=sg,
role=role,
)
I tried to override the property, but it did not work, it just creates a new LaunchTemplateData section in the Cfn:
cfnLT = lt.node.default_child
cfnLT.add_override("LaunchTemplateData.MetadataOptionsProperty.HttpPutResponseHopLimit", "2")
Result
[~] AWS::EC2::LaunchTemplate Example Example489151D8
└─ [+] LaunchTemplateData
└─ {"MetadataOptionsProperty":{"HttpPutResponseHopLimit":"2"}}
Then I hacked this together, and while it looks awful, it does work:
cfnLT = lt.node.default_child
metadata_prop = ec2.CfnLaunchTemplate.MetadataOptionsProperty(http_put_response_hop_limit=2)
lt_data = cfnLT.launch_template_data
lt_data2 = ec2.CfnLaunchTemplate.LaunchTemplateDataProperty(**lt_data.__dict__["_values"], metadata_options=metadata_prop)
[~] AWS::EC2::LaunchTemplate Example Example489151D8
└─ [~] LaunchTemplateData
└─ [+] Added: .MetadataOptions
My question is, can we add support to metadata_options to the L2 Construct? And is there a better way to override this?
Other Information
No response
Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
CDK version used
2.39.1
Environment details (OS name and version, etc.)
Ubuntu 20.04
This issue has been classified as p2. That means a workaround is available or it is deemed a nice-to-have feature. Given the amount of work there is to do and the relative priority of this issue, the CDK team is unlikely to address it. That does not mean the issue will never be fixed! If someone from the community submits a PR to fix this issue, and the PR is small and straightforward enough, and meets the quality bars to be reviewed and merged with little effort we will accept that PR. PRs that do not build or need complex or multiple rounds of reviews are unlikely to be merged and will be closed to keep our backlog manageable.
In the mean time, remember that you can always use the escape hatch (https://docs.aws.amazon.com/cdk/v2/guide/cfn_layer.html) mechanism to have fine control over the CloudFormation output you want. We will keep the issue open for discoverability, to collect upvotes, and to facilitate discussion around this topic.
We use +1s on this issue to help prioritize our work, and are happy to re-evaluate the prioritization of this issue based on community feedback. You can reach out to the cdk.dev community on Slack (https://cdk.dev/) to solicit support for reprioritization.
Same escape hatch but for TypeScript:
const cfnLT = lt.node.defaultChild as ec2.CfnLaunchTemplate;
const ltData = cfnLT.launchTemplateData as ec2.CfnLaunchTemplate.LaunchTemplateDataProperty;
const ltData2: ec2.CfnLaunchTemplate.LaunchTemplateDataProperty = {
...ltData,
metadataOptions: {
...ltData.metadataOptions,
httpPutResponseHopLimit: 2
}
};
cfnLT.launchTemplateData = ltData2;
working on it.
⚠️COMMENT VISIBILITY WARNING⚠️
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.