Table of Contents

Class EC2InstanceMetadata

Namespace
Amazon.Util
Assembly
AWSSDK.Core.dll

Provides access to EC2 instance metadata when running on an EC2 instance. If this class is used on a non-EC2 instance, the properties in this class will return null.

public static class EC2InstanceMetadata
Inheritance
EC2InstanceMetadata
Inherited Members

Remarks

Amazon EC2 instances can access instance-specific metadata, as well as data supplied when launching the instances, using a specific URI.

You can use this data to build more generic AMIs that can be modified by configuration files supplied at launch time. For example, if you run web servers for various small businesses, they can all use the same AMI and retrieve their content from the Amazon S3 bucket you specify at launch. To add a new customer at any time, simply create a bucket for the customer, add their content, and launch your AMI.

More information about EC2 Metadata http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html

Fields

AWS_EC2_METADATA_DISABLED

public static readonly string AWS_EC2_METADATA_DISABLED

Field Value

string

EC2_APITOKEN_URL

[Obsolete("EC2_APITOKEN_URL is obsolete, refer to EC2ApiTokenUrl instead to respect environment and profile overrides.")]
public static readonly string EC2_APITOKEN_URL

Field Value

string

EC2_DYNAMICDATA_ROOT

[Obsolete("EC2_DYNAMICDATA_ROOT is obsolete, refer to EC2DynamicDataRoot instead to respect environment and profile overrides.")]
public static readonly string EC2_DYNAMICDATA_ROOT

Field Value

string

EC2_METADATA_ROOT

[Obsolete("EC2_METADATA_ROOT is obsolete, refer to EC2MetadataRoot instead to respect environment and profile overrides.")]
public static readonly string EC2_METADATA_ROOT

Field Value

string

EC2_METADATA_SVC

[Obsolete("EC2_METADATA_SVC is obsolete, refer to ServiceEndpoint instead to respect environment and profile overrides.")]
public static readonly string EC2_METADATA_SVC

Field Value

string

EC2_USERDATA_ROOT

[Obsolete("EC2_USERDATA_ROOT is obsolete, refer to EC2UserDataRoot instead to respect environment and profile overrides.")]
public static readonly string EC2_USERDATA_ROOT

Field Value

string

LATEST

public static readonly string LATEST

Field Value

string

Properties

AmiId

The AMI ID used to launch the instance.

public static string AmiId { get; }

Property Value

string

AmiLaunchIndex

The index of this instance in the reservation.

public static string AmiLaunchIndex { get; }

Property Value

string

AmiManifestPath

The manifest path of the AMI with which the instance was launched.

public static string AmiManifestPath { get; }

Property Value

string

AncestorAmiIds

The AMI IDs of any instances that were rebundled to create this AMI. Will only exist if the AMI manifest file contained an ancestor-amis key.

public static IEnumerable<string> AncestorAmiIds { get; }

Property Value

IEnumerable<string>

AvailabilityZone

The Availability Zone in which the instance launched.

public static string AvailabilityZone { get; }

Property Value

string

BlockDeviceMapping

The virtual devices associated with the ami, root, ebs, and swap.

public static IDictionary<string, string> BlockDeviceMapping { get; }

Property Value

IDictionary<string, string>

EC2ApiTokenUrl

URI to retrieve the IMDS API token

public static string EC2ApiTokenUrl { get; }

Property Value

string

EC2DynamicDataRoot

Root URI to retrieve dynamic instance data

public static string EC2DynamicDataRoot { get; }

Property Value

string

EC2MetadataRoot

Root URI to retrieve instance metadata

public static string EC2MetadataRoot { get; }

Property Value

string

EC2UserDataRoot

Root URI to retrieve instance user data

public static string EC2UserDataRoot { get; }

Property Value

string

Hostname

The private hostname of the instance. In cases where multiple network interfaces are present, this refers to the eth0 device (the device for which the device number is 0).

public static string Hostname { get; }

Property Value

string

IAMInstanceProfileInfo

Returns information about the last time the instance profile was updated, including the instance's LastUpdated date, InstanceProfileArn, and InstanceProfileId.

public static IAMInstanceProfileMetadata IAMInstanceProfileInfo { get; }

Property Value

IAMInstanceProfileMetadata

IAMSecurityCredentials

Returns the temporary security credentials (AccessKeyId, SecretAccessKey, SessionToken, and Expiration) associated with the IAM roles on the instance.

public static IDictionary<string, IAMSecurityCredentialMetadata> IAMSecurityCredentials { get; }

Property Value

IDictionary<string, IAMSecurityCredentialMetadata>

IdentityDocument

JSON containing instance attributes, such as instance-id, private IP address, etc

public static string IdentityDocument { get; }

Property Value

string

IdentityPkcs7

Used to verify the document's authenticity and content against the signature.

public static string IdentityPkcs7 { get; }

Property Value

string

IdentitySignature

Data that can be used by other parties to verify its origin and authenticity.

public static string IdentitySignature { get; }

Property Value

string

InstanceAction

Notifies the instance that it should reboot in preparation for bundling. Valid values: none | shutdown | bundle-pending.

public static string InstanceAction { get; }

Property Value

string

InstanceId

The ID of this instance.

public static string InstanceId { get; }

Property Value

string

InstanceMonitoring

Value showing whether the customer has enabled detailed one-minute monitoring in CloudWatch.

public static string InstanceMonitoring { get; }

Property Value

string

InstanceType

The type of instance.

public static string InstanceType { get; }

Property Value

string

IsIMDSEnabled

Returns whether requesting the EC2 Instance Metadata Service is enabled via the AWS_EC2_METADATA_DISABLED environment variable.

public static bool IsIMDSEnabled { get; }

Property Value

bool

KernelId

The ID of the kernel launched with this instance, if applicable.

public static string KernelId { get; }

Property Value

string

LocalHostname

The local hostname of the instance. In cases where multiple network interfaces are present, this refers to the eth0 device (the device for which device-number is 0).

public static string LocalHostname { get; }

Property Value

string

MacAddress

The instance's MAC address. In cases where multiple network interfaces are present, this refers to the eth0 device (the device for which device-number is 0).

public static string MacAddress { get; }

Property Value

string

NetworkInterfaces

The network interfaces on the instance.

public static IEnumerable<NetworkInterfaceMetadata> NetworkInterfaces { get; }

Property Value

IEnumerable<NetworkInterfaceMetadata>

PrivateIpAddress

The private IP address of the instance. In cases where multiple network interfaces are present, this refers to the eth0 device (the device for which device-number is 0).

public static string PrivateIpAddress { get; }

Property Value

string

ProductCodes

Product codes associated with the instance, if any.

public static IEnumerable<string> ProductCodes { get; }

Property Value

IEnumerable<string>

Proxy

Allows to configure the proxy used for HTTP requests. The default value is null.

public static IWebProxy Proxy { get; set; }

Property Value

IWebProxy

PublicKey

Public key. Only available if supplied at instance launch time.

public static string PublicKey { get; }

Property Value

string

RamdiskId

The ID of the RAM disk specified at launch time, if applicable.

public static string RamdiskId { get; }

Property Value

string

Region

The region in which the instance is running, extracted from the identity document data.

public static RegionEndpoint Region { get; }

Property Value

RegionEndpoint

ReservationId

ID of the reservation.

public static string ReservationId { get; }

Property Value

string

SecurityGroups

The names of the security groups applied to the instance.

public static IEnumerable<string> SecurityGroups { get; }

Property Value

IEnumerable<string>

ServiceEndpoint

Base endpoint of the instance metadata service. Returns the endpoint configured first via environment variable AWS_EC2_METADATA_SERVICE_ENDPOINT then the current profile's ec2_metadata_service_endpoint value. If a specific endpoint is not configured, it selects a pre-determined endpoint based on environment variable AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE then the current profile's ec2_metadata_service_endpoint_mode setting.

public static string ServiceEndpoint { get; }

Property Value

string

UserData

The metadata sent to the instance.

public static string UserData { get; }

Property Value

string

Methods

ClearTokenFlag()

public static void ClearTokenFlag()

FetchApiToken()

Fetches the api token to use with metadata requests.

public static string FetchApiToken()

Returns

string

The API token or null

GetData(string)

Return the metadata at the path

public static string GetData(string path)

Parameters

path string

Path at which to query the metadata; may be relative or absolute.

Returns

string

Data returned by the metadata service

GetData(string, int)

Return the metadata at the path

public static string GetData(string path, int tries)

Parameters

path string

Path at which to query the metadata; may be relative or absolute.

tries int

Number of attempts to make

Returns

string

Data returned by the metadata service

GetItems(string)

Return the list of items in the metadata at path.

public static IEnumerable<string> GetItems(string path)

Parameters

path string

Path at which to query the metadata; may be relative or absolute.

Returns

IEnumerable<string>

List of items returned by the metadata service

GetItems(string, int)

Return the list of items in the metadata at path.

public static IEnumerable<string> GetItems(string path, int tries)

Parameters

path string

Path at which to query the metadata; may be relative or absolute.

tries int

Number of attempts to make

Returns

IEnumerable<string>

List of items returned by the metadata service