Get EC2 Instance Metadata

Retrieve Amazon EC2 instance metadata from within the running instance.


aws.ec2metadata is a package for retrieving Amazon EC2 instance metadata from within the running instance. The package simply contains a single R list, metadata, that contains a number of functions for retrieving metadata from within an instance. Most of these functions return character strings, but some will return lists; they default to NULL if no value is returned.

library("aws.ec2metadata")
 
# get instance id
metadata$instance_id()
 
# get ami id
metadata$ami_id()
 
# check for IAM role (NULL if none specified)
(role <- metadata$iam_info())
# get role credentials
if (!is.null(role)) {
    metadata$iam_role("myrole")
}
 
# get an arbitrary metadata item
metadata$item("meta-data/placement/availability-zone")

Installation

CRAN Downloads Travis Build Status Appveyor Build Status codecov.io

This package is not yet on CRAN. To install the latest development version you can install from the cloudyr drat repository:

# latest stable version
install.packages("aws.ec2metadata", repos = c(cloudyr = "http://cloudyr.github.io/drat", getOption("repos")))

Or, to pull a potentially unstable version directly from GitHub:

if (!require("remotes")) {
    install.packages("remotes")
}
remotes::install_github("cloudyr/aws.ec2metadata")

cloudyr project logo

News

aws.ec2metadata 0.1.6

  • Added new functions: is_ecs() to check whether R is running in an Elastic Container Store (ECS) instance, and ecs_metadata() to retreive credentials from the container. (#2, h/t @jon-mago)

aws.ec2metadata 0.1.5

  • Now supports querying ECS task role

aws.ec2metadata 0.1.4

  • Previous .onLoad() functionality added in 0.1.3 is now moved to .onAttach() to comply with CRAN policy.

aws.ec2metadata 0.1.3

  • Added a function instance_document() that returns a list of the "instance identity document" information. This is useful for identifying the region an instance is running in.
  • When the package is loaded on an EC2 instance (as identified by is_ec2() during package load), the package attempts to set the AWS_DEFAULT_REGION environment variable if it has not already been specified. This helps handle request signing.

aws.ec2metadata 0.1.2

  • Added a function is_ec2() that returns a logical based on whether metadata is retrievable.

aws.ec2metadata 0.1.1

  • Initial release.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("aws.ec2metadata")

0.2.0 by Jonathan Stott, 3 days ago


https://github.com/cloudyr/aws.ec2metadata


Report a bug at https://github.com/cloudyr/aws.ec2metadata/issues


Browse source code at https://github.com/cran/aws.ec2metadata


Authors: Thomas J. Leeper [aut] , Jonathan Stott [cre, aut]


Documentation:   PDF Manual  


GPL (>= 2) license


Imports curl, jsonlite


Imported by awspack.

Suggested by aws.signature.


See at CRAN