We use machine learning technology to do auto-translation. Click "English" on top navigation bar to check Chinese version.
Get the full benefits of IMDSv2 and disable IMDSv1 across your Amazon Web Services infrastructure
The
- IMDSv2 requires the creation of a secret token in a simple HTTP PUT request to start the session, which must be used to retrieve information in IMDSv2 calls.
- The IMDSv2 session token must be used as a header in subsequent IMDSv2 requests to retrieve information from IMDS. Unlike a static token or fixed header, a session and its token are destroyed when the process using the token terminates. IMDSv2 sessions can last up to six hours.
- A session token can only be used directly from the EC2 instance where that session began.
- You can reuse a token or create a new token with every request.
- Session token PUT requests are blocked if they contain an X-forwarded-for header.
In a previous
You won’t be able to get the full benefits of IMDSv2 until you disable IMDSv1. While IMDS is provided by the instance itself, the calls to IMDS are from your software. This means your software must support IMDSv2 before you can disable IMDSv1. In addition to Amazon Web Services SDKs, CLIs, and tools like the
Amazon Web Services customers who want to get the benefits of IMDSv2 have told us they want to use IMDSv2 across both new and existing, long-running Amazon Web Services infrastructure. This blog post shows you scalable solutions to identify existing infrastructure that is providing IMDSv1, how to transition to IMDSv2 on your infrastructure, and how to completely disable IMDSv1. After reviewing this blog, you will be able to set new Amazon EC2 launches to IMDSv2. You will also learn how to identify existing software making IMDSv1 calls, so you can take action to update your software and then require IMDSv2 on existing EC2 infrastructure.
Identifying IMDSv1-enabled EC2 instances
The first step in transitioning to IMDSv2 is to identify all existing IMDSv1-enabled EC2 instances. You can do this in various ways.
Using the console
You can identify IMDSv1-enabled instances using the IMDSv2 attribute column in the Amazon EC2 page in the
To view the IMDSv2 attribute column:
- Open the Amazon EC2 console and go to Instances.
- Choose the settings icon in the top right.
- Scroll down to IMDSv2 , turn on the slider.
- Choose Confirm .
This gives you the IMDS status of your instances. A status of optional means that IMDSv1 is enabled on the instance and required means that IMDSv1 is disabled.

Figure 1: Example of IMDS versions for EC2 instances in the console
Using the Amazon Web Services CLI
You can identify IMDSv1-enabled instances using the
Using Amazon Web Services Config

Figure 2: Example of noncompliant EC2 instances in the Amazon Web Services Config console
After this Amazon Web Services Config rule is enabled, you can set up
Using Security Hub
Security Hub has an Amazon EC2 control (

Figure 3: Example of Amazon Web Services Security Hub showing noncompliant EC2 instances
Using
Identifying if EC2 instances are making IMDSv1 calls
Not all of your software will be making IMDSv1 calls; your dependent libraries and tools might already be compatible with IMDSv2. However, to mitigate against compatibility issues in requiring IMDSv2 and disabling IMDSv1 entirely, you must check for remaining IMDSv1 calls from your software. After you’ve identified that there are instances with IMDSv1 enabled, investigate if your software is making IMDSv1 calls. Most applications make IMDSv1 calls at instance launch and shutdown. For long running instances, we recommend monitoring IMDSv1 calls during a launch or a stop and restart cycle.
You can check whether your software is making IMDSv1 calls by checking the
Steps to check IMDSv1 usage with CloudWatch
- Open the CloudWatch console.
- Go to Metrics and then All Metrics .
- Select EC2 and then choose Per-Instance Metrics .
- Search and add the Metric MetadataNoToken for the instances you’re interested in.

Figure 4: CloudWatch dashboard for MetadataNoToken per-instance metric
You can use

Figure 5: Using CloudWatch expressions to view account wide metrics for MetadataNoToken
You can combine SEARCH and SORT expressions in CloudWatch to help identify the instances using IMDSv1.

Figure 6: Another example of using CloudWatch expressions to view account wide metrics
If you have multiple Amazon Web Services accounts or use Amazon Web Services Organizations, you can set up a centralized monitoring account using
IMDS Packet Analyzer
The IMDS Packet Analyzer is an open source tool that identifies and logs IMDSv1 calls from your software, including software start-up on your instance. This tool can assist in identifying the software making IMDSv1 calls on EC2 instances, allowing you to pinpoint exactly what you need to update to get your software ready to use IMDSv2. You can run the IMDS Packet Analyzer from a command line or install it as a service. For more information, see
Disabling IMDSv1 and maintaining only IMDSv2 instances
After you’ve monitored and verified that the software on your EC2 instances isn’t making IMDSv1 calls, you can disable IMDSv1 on those instances. For all compatible workloads, we recommend using
You can also create and modify AMIs and EC2 instances to disable IMDSv1.
To create a new instance
For new instances, you can disable IMDSv1 and enable IMDSv2 by specifying the metadata-options parameter using the run-instance CLI command.
To modify the running instance
To configure a new AMI
To modify an existing AMI
Using the console
If you’re using the console to launch instances, after selecting Launch Instance from Amazon Web Services Console , choose the Advanced details tab, scroll down to Metadata version and select V2 only (token required) .

Figure 7: Modifying IMDS version using the console
Using EC2 launch templates
You can use an

Figure 8: Modifying the IMDS version in the EC2 launch templates
Using CloudFormation with EC2 launch templates
When creating an
In this state, retrieving the
Using Systems Manager automation runbook
You can run the
- Open the
Systems Manager console , and then select Automation from the navigation pane. - Choose Execute automation .
- On the Owned by Amazon tab, for Automation document , enter EnforceEC2InstanceIMDSv2 , and then press Enter.
- Choose EnforceEC2InstanceIMDSv2 document, and then choose Next .
- For Execute automation document , choose Simple execution .
Note : If you need to run the automation on multiple targets, then choose Rate Control .
- For Input parameters , enter the ID of EC2 instance under InstanceId
- For AutomationAssumeRole , select a role.
Note : To change the target EC2 instance, the AutomationAssumeRole must have ec2:ModifyInstanceMetadataOptions and ec2:DescribeInstances permissions. For more information about creating the assume role for Systems Manager Automation, see
Create a service role for Automation . - Choose Execute .
Using the Amazon Web Services CDK
If you use the
Using Amazon Web Services SDK
The new clients for
Maintain only IMDSv2 EC2 instances
To maintain only IMDSv2 instances, you can implement service control policies and IAM policies that verify that users and software on your EC2 instances can only use
You can find more details on applicable service control policies (SCPs) and IAM policies
Restricting credential usage using condition keys
As an additional layer of defence, you can restrict the use of your Amazon EC2 role credentials to work only when used in the EC2 instance to which they are issued. This control is complementary to IMDSv2 since both can work together. The
Conclusion
You won’t be able to get the full benefits of IMDSv2 until you disable IMDSv1. In this blog post, we showed you how to identify IMDSv1-enabled EC2 instances and how to determine if and when your software is making IMDSv1 calls. We also showed you how to disable IMDSv1 on new and existing EC2 infrastructure after your software is no longer making IMDSv1 calls. You can use these tools to transition your existing EC2 instances, and set your new EC2 launches, to use only IMDSv2.
If you have feedback about this post, submit comments in the Comments section below. If you have questions about this post, start a new thread on the
Want more Amazon Web Services Security news? Follow us on
The mentioned AWS GenAI Services service names relating to generative AI are only available or previewed in the Global Regions. Amazon Web Services China promotes AWS GenAI Services relating to generative AI solely for China-to-global business purposes and/or advanced technology introduction.