CmdID

CmdID / aws / aws ec2

aws ec2 modify-instance-metadata-options

Modify the instance metadata parameters on a running or stopped instance. AWS CLI reference

3 examples 7 options Its page in the AWS CLI reference

Opens CmdID with your command. It is read in your browser and sent nowhere.

Examples

from aws-cli, each command read by CmdID

Example 1: To enable IMDSv2

The following modify-instance-metadata-options example configures the use of IMDSv2 on the specified instance.

aws ec2 modify-instance-metadata-options --instance-id i-1234567898abcdef0 --http-tokens required --http-endpoint enabledIdentify
--instance-idThe ID of the instance.
--http-tokensIndicates whether IMDSv2 is required.
--http-endpointEnables or disables the HTTP metadata endpoint on your instances.
Its output
{
    "InstanceId": "i-1234567898abcdef0",
    "InstanceMetadataOptions": {
        "State": "pending",
        "HttpTokens": "required",
        "HttpPutResponseHopLimit": 1,
        "HttpEndpoint": "enabled"
    }
}

For more information, see Instance metadata in the Amazon EC2 User Guide.

Example 2: To disable instance metadata

The following modify-instance-metadata-options example disables the use of all versions of instance metadata on the specified instance.

aws ec2 modify-instance-metadata-options --instance-id i-1234567898abcdef0 --http-endpoint disabledIdentify
--instance-idThe ID of the instance.
--http-endpointEnables or disables the HTTP metadata endpoint on your instances.
Its output
{
    "InstanceId": "i-1234567898abcdef0",
    "InstanceMetadataOptions": {
        "State": "pending",
        "HttpTokens": "required",
        "HttpPutResponseHopLimit": 1,
        "HttpEndpoint": "disabled"
    }
}

For more information, see Instance metadata in the Amazon EC2 User Guide.

Example 3: To enable instance metadata IPv6 endpoint for your instance

The following modify-instance-metadata-options example turns on the IPv6 endpoint for the instance metadata service. By default, the IPv6 endpoint is disabled. This is true even if you have launched an instance into an IPv6-only subnet. The IPv6 endpoint for IMDS is only accessible on instances built on the Nitro System.

aws ec2 modify-instance-metadata-options --instance-id i-1234567898abcdef0 --http-protocol-ipv6 enabled --http-endpoint enabledIdentify
--instance-idThe ID of the instance.
--http-protocol-ipv6Enables or disables the IPv6 endpoint for the instance metadata service.
--http-endpointEnables or disables the HTTP metadata endpoint on your instances.
Its output
{
    "InstanceId": "i-1234567898abcdef0",
    "InstanceMetadataOptions": {
        "State": "pending",
        "HttpTokens": "required",
        "HttpPutResponseHopLimit": 1,
        "HttpEndpoint": "enabled",
        "HttpProtocolIpv6": "enabled"
    }
}

For more information, see Instance metadata in the Amazon EC2 User Guide.

Options

7 in the AWS CLI reference
--dry-runChecks whether you have the required permissions for the action, without actually making the request, and provides an error response.
--http-endpointEnables or disables the HTTP metadata endpoint on your instances.
--http-protocol-ipv6Enables or disables the IPv6 endpoint for the instance metadata service.
--http-put-response-hop-limitThe desired HTTP PUT response hop limit for instance metadata requests.
--http-tokensIndicates whether IMDSv2 is required.
--instance-idThe ID of the instance.
--instance-metadata-tagsSet to enabled to allow access to instance tags from the instance metadata.