Skip to content

Commit

Permalink
version 0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
leeper authored and cran-robot committed Apr 3, 2018
1 parent 058bc94 commit dae2a46
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 17 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: aws.ec2metadata
Type: Package
Title: Get EC2 Instance Metadata
Version: 0.1.2
Date: 2017-06-29
Version: 0.1.4
Date: 2018-04-02
Authors@R: c(person("Thomas J.", "Leeper", role = c("aut", "cre"),
email = "thosjleeper@gmail.com"))
Description: Retrieve Amazon EC2 instance metadata from within the running instance.
Expand All @@ -12,8 +12,8 @@ BugReports: https://github.com/cloudyr/aws.ec2metadata/issues
Imports: curl, jsonlite
RoxygenNote: 6.0.1
NeedsCompilation: no
Packaged: 2017-06-30 14:49:15 UTC; THOMAS
Packaged: 2018-04-02 21:28:34 UTC; THOMAS
Author: Thomas J. Leeper [aut, cre]
Maintainer: Thomas J. Leeper <thosjleeper@gmail.com>
Repository: CRAN
Date/Publication: 2017-06-30 17:19:40 UTC
Date/Publication: 2018-04-03 07:45:54 UTC
11 changes: 6 additions & 5 deletions MD5
@@ -1,7 +1,8 @@
405fa5c4d5831b9e3f1c074985a9ada2 *DESCRIPTION
0cc685d45f8c103eebeeaa5d1e4d38de *NAMESPACE
41471f25499eda464b3689dd9031e1b4 *NEWS.md
3b050e4089b783294477b8b411afcbd5 *R/aws.ec2metadata-package.R
89967f5aaff82da28c57cc10611f4a04 *DESCRIPTION
f7dbef91aec243ba9698c68a0b3d50ea *NAMESPACE
a49099f9da864516507033d50558ca58 *NEWS.md
d041ec247bb6db1602649aeca1bca2d0 *R/aws.ec2metadata-package.R
58bf6f90e895e7155df5e50c99bba326 *R/onLoad.R
d4e152223ef91d1cb33445013f7c03ef *README.md
eab6c62029e39bae5d6faa9981a8d2d5 *inst/CITATION
6ad437f305e7b8be192c797eab30b042 *man/ec2metadata.Rd
1ab2168f083054ef4f57c4a68bd1ca82 *man/ec2metadata.Rd
1 change: 1 addition & 0 deletions NAMESPACE
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(instance_document)
export(is_ec2)
export(metadata)
importFrom(curl,curl_fetch_memory)
Expand Down
13 changes: 11 additions & 2 deletions NEWS.md
@@ -1,7 +1,16 @@
# CHANGES TO aws.ec2metadata 0.1.2
# 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"](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html) 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.

# CHANGES TO aws.ec2metadata 0.1.1
# aws.ec2metadata 0.1.1

* Initial release.
21 changes: 18 additions & 3 deletions R/aws.ec2metadata-package.R
Expand Up @@ -47,19 +47,30 @@ is_ec2 <- function() {
}
}

#' @rdname ec2metadata
#' @importFrom jsonlite fromJSON
#' @export
instance_document <- function() {
jsonlite::fromJSON(get_instance_metadata(item = "dynamic/instance-identity/document"))
}

#' @rdname ec2metadata
#' @details \code{is_ec2} returns a logical for whether the current R session appears to be running in an EC2 instance.
#'
#' \code{instance_document} returns a list containing values from the \href{http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html}{Instance Identity Document}, including the instance ID, AMI ID, region, availability zone, etc.
#'
#' \code{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: \code{versions()} and \code{meta_data_items()} return the versions of the metadata, and the set of top-level metadata items, respectively.
#'
#' The function \code{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
#' @details Generally, this will return a character string containing the requested information, otherwise a \code{NULL} if the response is empty. The \code{iam_role()} function returns a list. An error will occur if, for some reason, the request otherwise fails.
#' The remaining functions in the list are aliases for potentially commonly needed metadata items.
#'
#' @return \code{is_ec2} returns a logical. Generally, all other functions will return a character string containing the requested information, otherwise a \code{NULL} if the response is empty. The \code{iam_role()} function returns a list. An error will occur if, for some reason, the request otherwise fails.
#' @examples
#' names(metadata)
#'
#' \dontrun{
#' if (is_ec2()) {
#' metadata$versions()
#' metadata$items()
#'
Expand All @@ -74,6 +85,10 @@ is_ec2 <- function() {
#'
#' # get an arbitrary metadata item
#' metadata$item("meta-data/placement/availability-zone")
#'
#' # get region from instance identity document
#' instance_document()$region
#' }
#' }
#' @references \href{http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html}{Metadata Documentation}
#' @importFrom jsonlite fromJSON
Expand Down Expand Up @@ -129,7 +144,7 @@ metadata <- list(
get_instance_metadata(item = "meta-data/local-ipv4", ...)
},
availability_zone = function(...) {
get_instance_metadata(item = "placement/availability-zone", ...)
get_instance_metadata(item = "meta-data/placement/availability-zone", ...)
},
public_hostname = function(...) {
get_instance_metadata(item = "meta-data/public-hostname", ...)
Expand Down
9 changes: 9 additions & 0 deletions R/onLoad.R
@@ -0,0 +1,9 @@
.onAttach <- function(libname, pkgname) {
if (is_ec2() && Sys.getenv("AWS_DEFAULT_REGION") == "") {
reg <- try(instance_document()$region, silent = TRUE)
if (!inherits(reg, "try-error")) {
Sys.setenv("AWS_DEFAULT_REGION" = reg)
packageStartupMessage(sprintf("Setting environment variable AWS_DEFAULT_REGION to '%s'", reg))
}
}
}
17 changes: 14 additions & 3 deletions man/ec2metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dae2a46

Please sign in to comment.