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
전문가
질문됨 한 달 전486회 조회
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
전문가
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전
profile picture
전문가
검토됨 한 달 전
profile picture
전문가
검토됨 한 달 전
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
전문가
답변함 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠