The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Type: Package
Title: Get EC2 Instance Metadata
Version: 0.2.0
Date: 2019-07-15
Description: Retrieve Amazon EC2 instance metadata from within the running instance.
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
URL: https://github.com/cloudyr/aws.ec2metadata
BugReports: https://github.com/cloudyr/aws.ec2metadata/issues
Imports: curl, jsonlite
RoxygenNote: 6.1.1
NeedsCompilation: no
Packaged: 2019-07-15 14:29:56 UTC; jon_m
Author: Thomas J. Leeper ORCID iD [aut], Jonathan Stott [cre, aut]
Maintainer: Jonathan Stott <jonathan.stott@magairports.com>
Repository: CRAN
Date/Publication: 2019-07-15 14:50:02 UTC

Get EC2 Instance Metadata

Description

Retrieve EC2 instance metadata from the instance

Usage

is_ec2()

instance_document()

metadata

is_ecs()

ecs_metadata(base_url = "http://169.254.170.2")

Arguments

base_url

Base URL for querying instance metadata

Format

An object of class list of length 26.

Details

is_ec2() returns a logical for whether the current R session appears to be running in an EC2 instance. is_ecs() returns a logical for whether the current R session appears to be running in an ECS task container.

instance_document returns a list containing values from the Instance Identity Document, including the instance ID, AMI ID, region, availability zone, etc.

metadata is a list of functions to return various metadata values for the currently running EC2 instance. These are only meant to be called from an EC2 instance; no guarantees are made about behavior on other platforms. Two functions: versions() and meta_data_items() return the versions of the metadata, and the set of top-level metadata items, respectively.

The function item() retrieves a particular metadata item specified by its full path.

The remaining functions in the list are aliases for potentially commonly needed metadata items.

The environment variable AWS_METADATA_SERVICE_TIMEOUT controls the timeout for instance metadata checks, and defaults to 1 second.

Value

is_ec2() and is_ecs() return a logical. Generally, all other functions will return a character string containing the requested information, otherwise a NULL if the response is empty. The iam_role() and ecs_metadata() functions return a list. An error will occur if, for some reason, the request otherwise fails.

Author(s)

Thomas J. Leeper <thosjleeper@gmail.com>

References

Metadata Documentation

Examples

names(metadata)

## Not run: 
if (is_ec2()) {
  metadata$versions()
  metadata$items()

  # get instance id
  metadata$instance_id()
  # get ami id
  metadata$ami_id()
  
  # get IAM role (NULL if none specified)
  metadata$iam_info()
  metadata$iam_role("myrole")

  # get an arbitrary metadata item
  metadata$item("meta-data/placement/availability-zone")
  
  # get region from instance identity document
  instance_document()$region
}

# Can also get ECS container metadata
if (is_ecs()) {
  # Get ECS role credentials
  metadata$ecs_task_role()
  # or
  ecs_metadata()
}

## End(Not run)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.