AWS Tools for Windows PowerShell
Command 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.

Synopsis

Outputs the values corresponding to one or more EC2 instance metadata categories. The metadata can be addressed using one or more category enumeration values or by specifying one or more category paths. The list of known categories can also be enumerated to the pipeline. For metadata that yields a single value, a single string is output. For metadata that yields an array of string values, the array is enumerated to the pipeline.

Syntax

ByCategory (Default)

Get-EC2InstanceMetadata
-Category <MetadataCategory[]>

ByPath

Get-EC2InstanceMetadata
-Path <String[]>

ListCategories

Get-EC2InstanceMetadata
-ListCategory <SwitchParameter>

Description

Return values of available metadata categories for the current EC2 instance. For more information on EC2 instance metadata see http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html.

Parameters

-Category <MetadataCategory[]>
One or more categories of instance metadata to retrieve.
Required?True
Position?Named
Accept pipeline input?False
-ListCategory <SwitchParameter>
Enumerates the categories that can be used with the -Category parameter to the pipeline.
Required?True
Position?Named
Accept pipeline input?False
-Path <String[]>
One or more instance metadata category paths to retrieve.
Required?True
Position?Named
Accept pipeline input?False

Inputs

This cmdlet does not accept pipeline input.

Outputs

Examples

Example 1

PS C:\> Get-EC2InstanceMetadata -ListCategory

AmiId
LaunchIndex
ManifestPath
AncestorAmiId
BlockDeviceMapping
InstanceId
InstanceType
LocalHostname
LocalIpv4
KernelId
AvailabilityZone
ProductCode
PublicHostname
PublicIpv4
PublicKey
RamdiskId
Region
ReservationId
SecurityGroup
UserData
InstanceMonitoring
IdentityDocument
IdentitySignature
IdentityPkcs7
Lists the available categories of instance metadata that can be queried.

Example 2

PS C:\> Get-EC2InstanceMetadata -Category AmiId

ami-b2e756ca
Returns the id of the Amazon Machine Image (AMI) that was used to launch the instance.

Example 3

PS C:\> Get-EC2InstanceMetadata -Category IdentityDocument
{
"availabilityZone" : "us-west-2a",
"devpayProductCodes" : null,
"marketplaceProductCodes" : null,
"version" : "2017-09-30",
"instanceId" : "i-01ed50f7e2607f09e",
"billingProducts" : [ "bp-6ba54002" ],
"instanceType" : "t2.small",
"pendingTime" : "2018-03-07T16:26:04Z",
"imageId" : "ami-b2e756ca",
"privateIp" : "10.0.0.171",
"accountId" : "563688378412",
"architecture" : "x86_64",
"kernelId" : null,
"ramdiskId" : null,
"region" : "us-west-2"
}
This example queries the JSON-formatted identity document for the instance.

Example 4

PS C:\> Get-EC2InstanceMetadata -Path "/network/interfaces/macs"

02:80:7f:ef:4c:e0/
This example uses a path query to obtain the network interface macs for the instance.

Example 5

PS C:\> Get-EC2InstanceMetadata -Path "/iam/info"

{
"Code" : "Success",
"LastUpdated" : "2018-03-08T03:38:40Z",
"InstanceProfileArn" : "arn:aws:iam::111122223333:instance-profile/MyLaunchRole_Profile",
"InstanceProfileId" : "AIPAI4...WVK2RW"
}
If there is an IAM role associated with the instance, returns information about the last time the instance profile was updated, including the instance's LastUpdated date, InstanceProfileArn, and InstanceProfileId.

Supported Version

AWS Tools for PowerShell: 2.x.y.z