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
EXPERT
asked a month ago448 views
2 Answers
1
Accepted Answer

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
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago
profile picture
EXPERT
reviewed a month ago
profile picture
EXPERT
reviewed a month ago
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
EXPERT
answered 22 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions