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.

# get instance id
# get ami id
# check for IAM role (NULL if none specified)
(role <- metadata$iam_info())
# get role credentials
if (!is.null(role)) {
# get an arbitrary metadata item


CRAN Downloads Travis Build Status Appveyor Build Status

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 = "", getOption("repos")))

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

if (!require("remotes")) {

cloudyr project logo


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.


0.2.0 by Jonathan Stott, 7 months ago

Report a bug at

Browse source code at

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

Documentation:   PDF Manual  

GPL (>= 2) license

Imports curl, jsonlite

Suggested by aws.signature.

See at CRAN