-
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: how to specify 'MetaData' for the instance? #25885
Comments
What metadata are you trying to add for the ec2 instance? Is it instance metadata? If yes, I am afraid cloudformation does not allow you to add MetadataOptions to ec2 instance and this is tracking in cloudformation coverage roadmap here. However, you may specify MetadataOptions in CfnLaunchConfiguration or in LauchTemplateDataProperty. Is this something you are looking for? |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Thank you @pahud for your response. I understand that "cloudformation does not allow you to add MetadataOptions to ec2 instance" however i was able to add the metadata using "addOverride" function. Further "CfnInstance" is equivalent to "AWS::EC2::Instance" in CloudFormation. As per doc[1] the "AWS::EC2::Instance" Resource type does support CFN Metadata. I have tested same in Cloudformation and it works. However in CDK "CfnInstance" resource "addMetadata(key, value)" construct can have only key-pair values while the instance metadata has to be quite large. Hence asking for a native function for same in "CfnInstance" resource. |
Please note the addMetadata() in the CfnInstance API reference is essentially to add CloudFormation Resource Metadata instead of EC2 instance metadata options. If you look at AWS::EC2::Instance there's no property that allows you to specify instance metadata options. If you really need to specify instance metadata options I believe you will need to specify that either in LauchConfiguration or LaunchTemplate as described above. |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Describe the feature
The "CfnInstance" Construct documentation[1] does not define how to specify 'MetaData' for the instance. And the "addMetadata(key, value)" construct can have only key-pair values while the instance metadata has to be quite large.
The solution that worked is using "addOverride" function:
As per Link[2] you can make use of "addOverride" function to add metadata to a 'CfnInstance' construct. An example[3] is as follows:
asgLaunchConfig.addOverride("Metadata", {
"AWS::CloudFormation::Init": {
"FOO": "BAR",
}
});
However ask from Service team:
[1] https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.html
[2] https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.html#addwbrmetadatakey-value
[3] #5087
[4] #777
Use Case
NA
Proposed Solution
NA
Other Information
NA
Acknowledgements
CDK version used
V2
Environment details (OS name and version, etc.)
MAC
The text was updated successfully, but these errors were encountered: