Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Amazon EC2 instance metadata - AWS SDKs and Tools

Amazon EC2 instance metadata

Note

For help in understanding the layout of settings pages, or in interpreting the Support by AWS SDKs and tools table that follows, see Understanding the settings pages of this guide.

Amazon EC2 provides a service on instances called the Instance Metadata Service (IMDS). To learn more about this service, see Work with instance metadata in the Amazon EC2 User Guide. When attempting to retrieve credentials on an Amazon EC2 instance that has been configured with an IAM role, the connection to the instance metadata service is adjustable.

Configure this functionality by using the following:

metadata_service_num_attempts - shared AWS config file setting
AWS_METADATA_SERVICE_NUM_ATTEMPTS - environment variable

This setting specifies the number of total attempts to make before giving up when attempting to retrieve data from the instance metadata service.

Default value: 1

Valid values: Number greater than or equal to 1.

metadata_service_timeout - shared AWS config file setting
AWS_METADATA_SERVICE_TIMEOUT - environment variable

Specifies the number of seconds before timing out when attempting to retrieve data from the instance metadata service.

Default value: 1

Valid values: Number greater than or equal to 1.

Example of setting these values in the config file:

[default] metadata_service_num_attempts=10 metadata_service_timeout=10

Linux/macOS example of setting environment variables via command line:

export AWS_METADATA_SERVICE_NUM_ATTEMPTS=10 export AWS_METADATA_SERVICE_TIMEOUT=10

Windows example of setting environment variables via command line:

setx AWS_METADATA_SERVICE_NUM_ATTEMPTS 10 setx AWS_METADATA_SERVICE_TIMEOUT 10

Support by AWS SDKs and tools

The following SDKs support the features and settings described in this topic. Any partial exceptions are noted. Any JVM system property settings are supported by the AWS SDK for Java and the AWS SDK for Kotlin only.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.