How to change instance metadata with "AWS::EC2::Instance" when launching EC2 with CloudFormation

0

Hello.

I would like to set "IMDSv2" in the instance metadata option when creating an EC2 instance using CloudFormation.
Looking at the documentation below, it seems that you need to create a launch template.
However, I think it's a bit of a roundabout procedure to create a startup template when you just want to start up one EC2 machine.
How do you enable IMDSv2 when creating EC2 from CloudFormation?
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-IMDS-new-instances.html

I saw the GitHub issue below, but it didn't seem like any progress was being made.
https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/655

profile picture
专家
已提问 1 个月前487 查看次数
2 回答
1
已接受的回答

Hi Riku,

Yes, it required a Launch template at this point until the issue you link to is fixed

But, to minimize your pain, you can find the proper template in this article: https://blog.karims.cloud/2020/11/15/practical-implemenation-of-imdsv2.html

Best,

Didier

profile pictureAWS
专家
已回答 1 个月前
profile picture
专家
已审核 1 个月前
profile picture
专家
已审核 1 个月前
profile picture
专家
已审核 1 个月前
0

With the CDK, you can set the requireImdsv2 property to true when creating EC2 instances. For example:

new ec2.Instance(this, 'Instance', {
  requireImdsv2: true
})

By setting requireImdsv2 to true, any instances launched through the CloudFormation stack will only be able to use IMDSv2 to retrieve instance metadata. IMDSv1 will be disabled.

This allows you to enforce IMDSv2 for new EC2 instances in CloudFormation without needing to define a separate launch template. The CDK takes care of configuring the necessary instance metadata options behind the scenes.

https://docs.aws.amazon.com/drs/latest/userguide/set-imdsv2.html

profile picture
专家
已回答 1 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则