AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

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.

Inheritance Hierarchy

System.Object
  Amazon.Util.EC2InstanceMetadata

Namespace: Amazon.Util
Assembly: AWSSDK.Core.dll
Version: 3.x.y.z

Syntax

C#
public static class EC2InstanceMetadata

The EC2InstanceMetadata type exposes the following members

Properties

NameTypeDescription
Public Property Static Property AmiId System.String

The AMI ID used to launch the instance.

Public Property Static Property AmiLaunchIndex System.String

The index of this instance in the reservation.

Public Property Static Property AmiManifestPath System.String

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

Public Property Static Property AncestorAmiIds System.Collections.Generic.IEnumerable<System.String>

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 Property Static Property AvailabilityZone System.String

The Availability Zone in which the instance launched.

Public Property Static Property BlockDeviceMapping System.Collections.Generic.IDictionary<System.String, System.String>

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

Public Property Static Property EC2ApiTokenUrl System.String

URI to retrieve the IMDS API token

Public Property Static Property EC2DynamicDataRoot System.String

Root URI to retrieve dynamic instance data

Public Property Static Property EC2MetadataRoot System.String

Root URI to retrieve instance metadata

Public Property Static Property EC2MetadataV1Disabled System.Boolean

Controls whether request EC2 metadata v1 fallback is disabled.

Public Property Static Property EC2UserDataRoot System.String

Root URI to retrieve instance user data

Public Property Static Property Hostname System.String

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 Property Static Property IAMInstanceProfileInfo Amazon.Util.IAMInstanceProfileMetadata

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

Public Property Static Property IAMSecurityCredentials System.Collections.Generic.IDictionary<System.String, Amazon.Util.IAMSecurityCredentialMetadata>

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

Public Property Static Property IdentityDocument System.String

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

Public Property Static Property IdentityPkcs7 System.String

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

Public Property Static Property IdentitySignature System.String

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

Public Property Static Property InstanceAction System.String

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

Public Property Static Property InstanceId System.String

The ID of this instance.

Public Property Static Property InstanceMonitoring System.String

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

Public Property Static Property InstanceType System.String

The type of instance.

Public Property Static Property IsIMDSEnabled System.Boolean

If set to true the SDK logic for falling back to V1 will be disabled. When using the SDK on an EC2 instance that has configured instance metadata service to use V1 only, a InvalidOperationException exception will be thrown when attempting to access the metadata in EC2 instance metadata.This includes AWS credentials and region information. The default value is false.

Public Property Static Property KernelId System.String

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

Public Property Static Property LocalHostname System.String

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 Property Static Property MacAddress System.String

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 Property Static Property NetworkInterfaces System.Collections.Generic.IEnumerable<Amazon.Util.NetworkInterfaceMetadata>

The network interfaces on the instance.

Public Property Static Property PrivateIpAddress System.String

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 Property Static Property ProductCodes System.Collections.Generic.IEnumerable<System.String>

Product codes associated with the instance, if any.

Public Property Static Property Proxy System.Net.IWebProxy

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

Public Property Static Property PublicKey System.String

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

Public Property Static Property RamdiskId System.String

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

Public Property Static Property Region Amazon.RegionEndpoint

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

Public Property Static Property ReservationId System.String

ID of the reservation.

Public Property Static Property SecurityGroups System.Collections.Generic.IEnumerable<System.String>

The names of the security groups applied to the instance.

Public Property Static Property ServiceEndpoint System.String

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 Property Static Property UserData System.String

The metadata sent to the instance.

Methods

Note:

Asynchronous operations (methods ending with Async) in the table below are for .NET 4.5 or higher. For .NET 3.5 the SDK follows the standard naming convention of BeginMethodName and EndMethodName to indicate asynchronous operations - these method pairs are not shown in the table below.

NameDescription
Public Method Static Method ClearTokenFlag()
Public Method Static Method FetchApiToken()

Fetches the api token to use with metadata requests.

Public Method Static Method GetData(string)

Return the metadata at the path

Public Method Static Method GetData(string, int)

Return the metadata at the path

Public Method Static Method GetItems(string)

Return the list of items in the metadata at path.

Public Method Static Method GetItems(string, int)

Return the list of items in the metadata at path.

Fields

NameTypeDescription
Field Static Field AWS_EC2_METADATA_DISABLED System.String
Field Static Field EC2_APITOKEN_URL System.String
Field Static Field EC2_DYNAMICDATA_ROOT System.String
Field Static Field EC2_METADATA_ROOT System.String
Field Static Field EC2_METADATA_SVC System.String
Field Static Field EC2_USERDATA_ROOT System.String
Field Static Field LATEST System.String

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

Version Information

.NET Core App:
Supported in: 3.1

.NET Standard:
Supported in: 2.0

.NET Framework:
Supported in: 4.5, 4.0, 3.5