Skip to content

Commit

Permalink
version 0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-mago authored and cran-robot committed Apr 24, 2019
1 parent fc57151 commit c446803
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
22 changes: 13 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
Package: aws.ec2metadata
Type: Package
Title: Get EC2 Instance Metadata
Version: 0.1.5
Date: 2018-07-26
Authors@R: c(person("Thomas J.", "Leeper", role = c("aut", "cre"),
Version: 0.1.6
Date: 2019-04-23
Authors@R: c(person("Thomas J.", "Leeper", role = c("aut"),
email = "thosjleeper@gmail.com",
comment = c(ORCID = "0000-0003-4097-6326")))
comment = c(ORCID = "0000-0003-4097-6326")),
person("Jonathan", "Stott", role = c("cre", "aut"),
email = "jonathan.stott@magairports.com")
)
Description: Retrieve Amazon EC2 instance metadata from within the running instance.
License: GPL (>= 2)
URL: https://github.com/cloudyr/aws.ec2metadata
BugReports: https://github.com/cloudyr/aws.ec2metadata/issues
Imports: curl, jsonlite
RoxygenNote: 6.0.1
RoxygenNote: 6.1.1
NeedsCompilation: no
Packaged: 2018-07-26 11:51:21 UTC; THOMAS
Author: Thomas J. Leeper [aut, cre] (<https://orcid.org/0000-0003-4097-6326>)
Maintainer: Thomas J. Leeper <thosjleeper@gmail.com>
Packaged: 2019-04-24 07:51:49 UTC; jon_m
Author: Thomas J. Leeper [aut] (<https://orcid.org/0000-0003-4097-6326>),
Jonathan Stott [cre, aut]
Maintainer: Jonathan Stott <jonathan.stott@magairports.com>
Repository: CRAN
Date/Publication: 2018-07-26 12:20:03 UTC
Date/Publication: 2019-04-24 09:10:03 UTC
6 changes: 3 additions & 3 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
6002c4125dfa7041147d9b445c91afd5 *DESCRIPTION
5777fd65f91b9bcb3948987c91bb1c5e *DESCRIPTION
e84cb707181c9a0bc31bdaec89165422 *NAMESPACE
eed96bf2ab3ec78737ceca3252d93550 *NEWS.md
902053efee1a94503fccb2d755d75122 *R/aws.ec2metadata-package.R
3675dda5bcc07f384cb7a8c7de3b4625 *R/aws.ec2metadata-package.R
58bf6f90e895e7155df5e50c99bba326 *R/onLoad.R
7c738583674463290fcee218c865af9c *README.md
eab6c62029e39bae5d6faa9981a8d2d5 *inst/CITATION
043b2b92a7cfd8bdaefa6933fb6ed1e5 *man/ec2metadata.Rd
8f00787be0941ce755e9788fa6f6afe0 *man/ec2metadata.Rd
17 changes: 12 additions & 5 deletions R/aws.ec2metadata-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ instance_document <- function() {
}

#' @rdname ec2metadata
#' @details \code{is_ec2} returns a logical for whether the current R session appears to be running in an EC2 instance.
#' @details \code{is_ec2()} returns a logical for whether the current R session appears to be running in an EC2 instance. \code{is_ecs()} returns a logical for whether the current R session appears to be running in an ECS task container.
#'
#' \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.
#'
Expand All @@ -65,7 +65,7 @@ instance_document <- function() {
#'
#' 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.
#' @return \code{is_ec2()} and \code{is_ecs()} return 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()} and \code{ecs_metadata()} functions return a list. An error will occur if, for some reason, the request otherwise fails.
#' @examples
#' names(metadata)
#'
Expand Down Expand Up @@ -93,6 +93,8 @@ instance_document <- function() {
#' # Can also get ECS container metadata
#' if (is_ecs()) {
#' # Get ECS role credentials
#' metadata$ecs_task_role()
#' # or
#' ecs_metadata()
#' }
#' }
Expand Down Expand Up @@ -175,7 +177,11 @@ metadata <- list(
},
partition = function(...) {
get_instance_metadata(item = "meta-data/services/partition", ...)
},
ecs_task_role = function(...) {
ecs_metadata(...)
}

)

ENV_CONTAINER_CREDS <- "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
Expand All @@ -184,14 +190,15 @@ ENV_CONTAINER_CREDS <- "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
#' @export
is_ecs <- function() {
container_relative <- Sys.getenv(ENV_CONTAINER_CREDS)
return(!is.null(container_relative))
return(!is.null(container_relative)&&(container_relative != ""))
}

#' @rdname ec2metadata
#' @param base_url Base URL for querying instance metadata
#' @export
ecs_metadata <- function() {
ecs_metadata <- function(base_url="http://169.254.170.2") {
container_relative <- Sys.getenv(ENV_CONTAINER_CREDS)
uri <- paste0("http://169.254.170.2", container_relative)
uri <- paste0(base_url, container_relative)
response <- try(curl::curl_fetch_memory(uri), silent = TRUE)
if (inherits(response, "try-error")) {
out <- NULL
Expand Down
13 changes: 9 additions & 4 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 c446803

Please sign in to comment.