Get EC2 Instance Metadata

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 on CRAN, but 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

Try the aws.ec2metadata package in your browser

Any scripts or data that you put into this service are public.

aws.ec2metadata documentation built on July 15, 2019, 5:02 p.m.