public class EC2MetadataUtils extends Object
You can disable the use of the EC2 Instance meta data service by either setting the
SDKGlobalConfiguration.AWS_EC2_METADATA_DISABLED_ENV_VAR
or
SDKGlobalConfiguration.AWS_EC2_METADATA_DISABLED_SYSTEM_PROPERTY
to 'true'(not case sensitive).
More information about Amazon EC2 Metadata
Migrating to AWS SDK for Java v2
The v2 equivalent of this class is Ec2MetadataClient
See Migration Guide for more information.
Modifier and Type | Class and Description |
---|---|
static class |
EC2MetadataUtils.IAMInfo
Information about the last time the instance profile was updated,
including the instance's LastUpdated date, InstanceProfileArn, and
InstanceProfileId.
|
static class |
EC2MetadataUtils.IAMSecurityCredential
The temporary security credentials (AccessKeyId, SecretAccessKey,
SessionToken, and Expiration) associated with the IAM role.
|
static class |
EC2MetadataUtils.InstanceInfo
This POJO is a best attempt to capture the instance info which is only
guaranteed to be a JSON document per
http://docs.aws.amazon.com/AWSEC2/latest
/UserGuide/ec2-instance-metadata.html
Instance info includes dynamic information about the current instance
such as region, instanceId, private IP address, etc.
|
static class |
EC2MetadataUtils.NetworkInterface
All of the metadata associated with a network interface on the instance.
|
Modifier and Type | Field and Description |
---|---|
static String |
SECURITY_CREDENTIALS_RESOURCE
Default resource path for credentials in the Amazon EC2 Instance Metadata Service.
|
Constructor and Description |
---|
EC2MetadataUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
getAmiId()
Get the AMI ID used to launch the instance.
|
static String |
getAmiLaunchIndex()
Get the index of this instance in the reservation.
|
static String |
getAmiManifestPath()
Get the manifest path of the AMI with which the instance was launched.
|
static List<String> |
getAncestorAmiIds()
Get the list of AMI IDs of any instances that were rebundled to created
this AMI.
|
static String |
getAvailabilityZone()
Get the Availability Zone in which the instance launched.
|
static Map<String,String> |
getBlockDeviceMapping()
Get the virtual devices associated with the ami, root, ebs, and swap.
|
static String |
getData(String path) |
static String |
getData(String path,
int tries) |
static String |
getEC2InstanceRegion()
Returns the current region of this running EC2 instance; or null if
it is unable to do so.
|
static String |
getHostAddressForEC2MetadataService()
Returns the host address of the Amazon EC2 Instance Metadata Service.
|
static EC2MetadataUtils.IAMInfo |
getIAMInstanceProfileInfo()
Get information about the last time the instance profile was updated,
including the instance's LastUpdated date, InstanceProfileArn, and
InstanceProfileId.
|
static Map<String,EC2MetadataUtils.IAMSecurityCredential> |
getIAMSecurityCredentials()
Returns the temporary security credentials (AccessKeyId, SecretAccessKey,
SessionToken, and Expiration) associated with the IAM roles on the
instance.
|
static String |
getInstanceAction()
Notifies the instance that it should reboot in preparation for bundling.
|
static String |
getInstanceId()
Get the ID of this instance.
|
static EC2MetadataUtils.InstanceInfo |
getInstanceInfo()
The instance info is only guaranteed to be a JSON document per
http://docs
.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
|
static String |
getInstanceSignature()
Get the signature of the instance.
|
static String |
getInstanceType()
Get the type of the instance.
|
static List<String> |
getItems(String path) |
static List<String> |
getItems(String path,
int tries) |
static String |
getLocalHostName()
Get the local hostname of the instance.
|
static String |
getMacAddress()
Get the MAC address of the instance.
|
static List<EC2MetadataUtils.NetworkInterface> |
getNetworkInterfaces()
Get the list of network interfaces on the instance.
|
static String |
getPrivateIpAddress()
Get the private IP address of the instance.
|
static List<String> |
getProductCodes()
Get the list of product codes associated with the instance, if any.
|
static String |
getPublicKey()
Get the public key.
|
static String |
getRamdiskId()
Get the ID of the RAM disk specified at launch time, if applicable.
|
static String |
getReservationId()
Get the ID of the reservation.
|
static List<String> |
getSecurityGroups()
Get the list of names of the security groups applied to the instance.
|
static String |
getUserData()
Get the metadata sent to the instance
|
public static final String SECURITY_CREDENTIALS_RESOURCE
public static String getAmiId()
public static String getAmiLaunchIndex()
public static String getAmiManifestPath()
public static List<String> getAncestorAmiIds()
public static String getInstanceAction()
public static String getInstanceId()
public static String getInstanceType()
public static String getLocalHostName()
public static String getMacAddress()
public static String getPrivateIpAddress()
public static String getAvailabilityZone()
public static List<String> getProductCodes()
public static String getPublicKey()
public static String getRamdiskId()
public static String getReservationId()
public static List<String> getSecurityGroups()
public static EC2MetadataUtils.IAMInfo getIAMInstanceProfileInfo()
public static EC2MetadataUtils.InstanceInfo getInstanceInfo()
This method is only a best attempt to capture the instance info as a typed object.
Get an InstanceInfo object with dynamic information about this instance.
public static String getInstanceSignature()
public static String getEC2InstanceRegion()
The instance info is only guaranteed to be a JSON document per http://docs .aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
public static Map<String,EC2MetadataUtils.IAMSecurityCredential> getIAMSecurityCredentials()
public static Map<String,String> getBlockDeviceMapping()
public static List<EC2MetadataUtils.NetworkInterface> getNetworkInterfaces()
public static String getUserData()
public static List<String> getItems(String path)
path
- Path to query.public static List<String> getItems(String path, int tries)
path
- Path to query.tries
- Number of attempts to query EC2 metadata service for items.public static String getHostAddressForEC2MetadataService()