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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南