From 68b36651fdf0f4c078974fb6e1cd6b97a5807875 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Mon, 13 Apr 2020 14:42:03 -0500 Subject: [PATCH 01/14] Bring this package back alive! For now I just redocumented and rebuilt, with my name added as maintainer. We'll see how that goes. --- .gitignore | 2 +- DESCRIPTION | 16 ++++++++++------ man/create_function.Rd | 28 ++++++++++++++++++++++------ man/invoke_function.Rd | 10 ++++++++-- man/lambdaHTTP.Rd | 17 +++++++++++++---- 5 files changed, 54 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 3a36669..09f53db 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ .Rproj.user .Rhistory .RData -aws.s3.Rproj +aws.lambda.Rproj diff --git a/DESCRIPTION b/DESCRIPTION index 311edb1..98be3ff 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,12 +1,16 @@ Package: aws.lambda Type: Package Title: AWS Lambda Client Package -Version: 0.1.6 -Date: 2017-07-01 -Authors@R: c(person("Thomas J.", "Leeper", role = c("aut"), +Version: 0.1.6.9000 +Date: 2020-04-13 +Authors@R: c( + person("Thomas J.", "Leeper", role = c("aut"), email = "thosjleeper@gmail.com", - comment = c(ORCID = "0000-0003-4097-6326"))) -Maintainer: ORPHANED + comment = c(ORCID = "0000-0003-4097-6326")), + person("Jon", "Harmon", role = c("ctb", "cre"), + email = "jonthegeek@gmail.com", + comment = c(ORCID = "0000-0003-4781-4346")) + ) Description: A simple client package for the Amazon Web Services ('AWS') Lambda 'API' . License: GPL (>= 2) Imports: @@ -21,4 +25,4 @@ Suggests: aws.iam URL: https://github.com/cloudyr/aws.lambda BugReports: https://github.com/cloudyr/aws.lambda/issues -RoxygenNote: 6.0.1 +RoxygenNote: 7.1.0 diff --git a/man/create_function.Rd b/man/create_function.Rd index 6cad986..8978d2e 100644 --- a/man/create_function.Rd +++ b/man/create_function.Rd @@ -6,13 +6,29 @@ \alias{make_function_version} \title{Manage AWS Lambda Functions} \usage{ -create_function(name, description = name, func, handler, role, - runtime = c("nodejs6.10", "nodejs4.3", "java8", "python2.7", - "dotnetcore1.0", "nodejs4.3-edge"), timeout = 3L, ...) +create_function( + name, + description = name, + func, + handler, + role, + runtime = c("nodejs6.10", "nodejs4.3", "java8", "python2.7", "dotnetcore1.0", + "nodejs4.3-edge"), + timeout = 3L, + ... +) -update_function(name, func, description, handler, role, - runtime = c("nodejs6.10", "nodejs4.3", "java8", "python2.7", - "dotnetcore1.0", "nodejs4.3-edge"), timeout = 3L, ...) +update_function( + name, + func, + description, + handler, + role, + runtime = c("nodejs6.10", "nodejs4.3", "java8", "python2.7", "dotnetcore1.0", + "nodejs4.3-edge"), + timeout = 3L, + ... +) make_function_version(name, description, ...) } diff --git a/man/invoke_function.Rd b/man/invoke_function.Rd index 4b0e6ca..18cb22c 100644 --- a/man/invoke_function.Rd +++ b/man/invoke_function.Rd @@ -4,8 +4,14 @@ \alias{invoke_function} \title{Invoke Lambda Function} \usage{ -invoke_function(name, qualifier, payload = NULL, type = c("RequestResponse", - "Event", "DryRun"), log = c("None", "Tail"), ...) +invoke_function( + name, + qualifier, + payload = NULL, + type = c("RequestResponse", "Event", "DryRun"), + log = c("None", "Tail"), + ... +) } \arguments{ \item{name}{A character string specifying the function name (either a full ARN or a max 64-character string). For functions other than \code{create_function} this can also be an object of class \dQuote{aws_lambda_function}.} diff --git a/man/lambdaHTTP.Rd b/man/lambdaHTTP.Rd index 70f4c98..5d52dd3 100644 --- a/man/lambdaHTTP.Rd +++ b/man/lambdaHTTP.Rd @@ -4,10 +4,19 @@ \alias{lambdaHTTP} \title{Execute AWS Lambda API Request} \usage{ -lambdaHTTP(verb = "GET", action, query = list(), headers = list(), - body = NULL, verbose = getOption("verbose", FALSE), - region = Sys.getenv("AWS_DEFAULT_REGION", "us-east-1"), key = NULL, - secret = NULL, session_token = NULL, ...) +lambdaHTTP( + verb = "GET", + action, + query = list(), + headers = list(), + body = NULL, + verbose = getOption("verbose", FALSE), + region = Sys.getenv("AWS_DEFAULT_REGION", "us-east-1"), + key = NULL, + secret = NULL, + session_token = NULL, + ... +) } \arguments{ \item{verb}{A character string specifying the HTTP verb to use.} From a5b8ec9202e6b3169cdd70be006ab76a1c66dcc7 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Mon, 13 Apr 2020 14:45:32 -0500 Subject: [PATCH 02/14] Add NEWS.md --- NEWS.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 88bafd5..7045bad 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,19 +1,23 @@ -# CHANGES TO aws.lambda 0.1.6 +# aws.lambda 0.1.6.9000 + +* New maintainer (@jonthegeek). + +# aws.lambda 0.1.6 * Change `get_account()` to `get_lambda_account()` to avoid namespace conflict with **aws.iam.** -# CHANGES TO aws.lambda 0.1.4 +# aws.lambda 0.1.4 * Bump **aws.signature** dependency to 0.3.4. -# CHANGES TO aws.lambda 0.1.3 +# aws.lambda 0.1.3 * Rename alias-related functions to avoid namespace clash with aws.iam. -# CHANGES TO aws.lambda 0.1.2 +# aws.lambda 0.1.2 * Update code and documentation. -# CHANGES TO aws.lambda 0.1.1 +# aws.lambda 0.1.1 * Initial release. From 087c1c22f03e5be3c7d2b04d75638d172605c4ff Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Mon, 13 Apr 2020 15:07:15 -0500 Subject: [PATCH 03/14] Updated travis to match aws.s3 --- .travis.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index ac182e4..e7c3291 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,12 +7,9 @@ matrix: dist: trusty sudo: required env: DRAT_DEPLOY=true - - os: osx - osx_image: xcode9.2 - - os: osx - osx_image: xcode7.3 - r_build_args: "--no-build-vignettes" - r_check_args: "--ignore-vignettes --no-examples" +# Travis is currently broken for macos R so disable +# - os: osx +# osx_image: xcode9.2 r_packages: - covr - drat From ae426efd37f5b766e7ba9fb0702ee54b221938f3 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Mon, 13 Apr 2020 15:58:35 -0500 Subject: [PATCH 04/14] Cleanup with goodpractice package. --- DESCRIPTION | 1 - NAMESPACE | 1 + R/http.R | 26 +++++++++++++------------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 98be3ff..31b13e0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,6 @@ Package: aws.lambda Type: Package Title: AWS Lambda Client Package Version: 0.1.6.9000 -Date: 2020-04-13 Authors@R: c( person("Thomas J.", "Leeper", role = c("aut"), email = "thosjleeper@gmail.com", diff --git a/NAMESPACE b/NAMESPACE index ffb0b89..a88ab28 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,6 +20,7 @@ export(make_function_version) export(update_function) export(update_function_alias) import(httr) +importFrom(aws.signature,locate_credentials) importFrom(aws.signature,signature_v4_auth) importFrom(base64enc,base64encode) importFrom(jsonlite,fromJSON) diff --git a/R/http.R b/R/http.R index 942b65e..0494daa 100644 --- a/R/http.R +++ b/R/http.R @@ -18,9 +18,9 @@ #' @import httr #' @importFrom utils str #' @importFrom jsonlite fromJSON toJSON -#' @importFrom aws.signature signature_v4_auth +#' @importFrom aws.signature signature_v4_auth locate_credentials #' @export -lambdaHTTP <- +lambdaHTTP <- function( verb = "GET", action, @@ -28,31 +28,31 @@ function( headers = list(), body = NULL, verbose = getOption("verbose", FALSE), - region = Sys.getenv("AWS_DEFAULT_REGION", "us-east-1"), - key = NULL, - secret = NULL, + region = Sys.getenv("AWS_DEFAULT_REGION", "us-east-1"), + key = NULL, + secret = NULL, session_token = NULL, ... ) { # locate and validate credentials - credentials <- locate_credentials(key = key, secret = secret, session_token = session_token, region = region, verbose = verbose) + credentials <- aws.signature::locate_credentials(key = key, secret = secret, session_token = session_token, region = region, verbose = verbose) key <- credentials[["key"]] secret <- credentials[["secret"]] session_token <- credentials[["session_token"]] region <- credentials[["region"]] - + # generate request signature d_timestamp <- format(Sys.time(), "%Y%m%dT%H%M%SZ", tz = "UTC") url <- paste0("https://lambda.", region, ".amazonaws.com", action) - - if (length(body)) { + + if (length(body)) { if (is.list(body)) { body <- jsonlite::toJSON(body, auto_unbox = TRUE) } } else { body <- NULL } - + headers[["host"]] <- paste0("lambda.",region,".amazonaws.com") headers[["x-amz-date"]] <- d_timestamp Sig <- signature_v4_auth( @@ -74,7 +74,7 @@ function( headers[["x-amz-security-token"]] <- session_token } H <- do.call("add_headers", headers) - + # execute request if (verb == "GET") { if (length(query)) { @@ -116,8 +116,8 @@ function( r <- POST(url, H, body = body, encode = "json", ...) } } - } - + } + if (http_error(r)) { h <- headers(r) content <- try(content(r, "parsed", encoding = "UTF-8"), silent = TRUE) From a02a57c5b2bf98e8ab7c9d6630fc1e7d96787e7d Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Tue, 14 Apr 2020 12:22:44 -0500 Subject: [PATCH 05/14] Verified functions.R Found and fixed a bug in delete_function (it was invoking delete_function_version instead of the main delete API). Manually tested all functions in this file to make sure they're invoking the proper APIs with proper query parameters. --- R/functions.R | 120 ++++++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 53 deletions(-) diff --git a/R/functions.R b/R/functions.R index dffbf2e..0b3b434 100644 --- a/R/functions.R +++ b/R/functions.R @@ -7,81 +7,95 @@ #' @param n An integer specifying the number of results to return. #' @template dots #' @return An object of class \dQuote{aws_lambda_function}. -#' @details \code{list_functions} lists all functions. \code{get_function} retrieves a specific function and \code{get_function_versions} retrieves all versions of that function. \code{get_function_configuration} returns the configuration details used when creating or updating the function. \code{delete_function} deletes a function, if you have permission to do so. +#' @details \code{list_functions} lists all functions. \code{get_function} +#' retrieves a specific function and \code{get_function_versions} retrieves +#' all versions of that function. \code{get_function_configuration} returns +#' the configuration details used when creating or updating the function. +#' \code{delete_function} deletes a function, if you have permission to do so. #' @references -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html}{API Reference: GetFunction} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListVersionsByFunction.html}{API Reference: ListVersionsByFunction} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html}{API Reference: ListFunctions} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunctionConfiguration.html}{API Reference: GetFunctionConfiguration} +#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html}{API +#' Reference: GetFunction} +#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListVersionsByFunction.html}{API +#' Reference: ListVersionsByFunction} +#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html}{API +#' Reference: ListFunctions} +#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunctionConfiguration.html}{API +#' Reference: GetFunctionConfiguration} #' @seealso \code{\link{create_function}}, \code{\link{update_function}} #' @export get_function <- function(name, qualifier, ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name) - query <- list() - if (!missing(qualifier)) { - query[["Qualifier"]] <- qualifier - } - r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) - structure(c(r[["Configuration"]], list(Code = r[["Code"]], Tags = r[["Tags"]])), - class = "aws_lambda_function") + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name) + query <- list() + if (!missing(qualifier)) { + query[["Qualifier"]] <- qualifier + } + r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) + structure( + c(r[["Configuration"]], list(Code = r[["Code"]], Tags = r[["Tags"]])), + class = "aws_lambda_function" + ) } #' @rdname functions #' @export list_functions <- function(marker, n, ...) { - act <- paste0("/2015-03-31/functions") - query <- list() - if (!missing(marker)) { - query[["Marker"]] <- marker - } - if (!missing(n)) { - query[["MaxItems"]] <- n - } - r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) - structure(lapply(r[["Functions"]], `class<-`, "aws_lambda_function"), - marker = r[["NextMarker"]]) + act <- paste0("/2015-03-31/functions") + query <- list() + if (!missing(marker)) { + query[["Marker"]] <- marker + } + if (!missing(n)) { + query[["MaxItems"]] <- n + } + r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) + structure( + lapply(r[["Functions"]], `class<-`, "aws_lambda_function"), + marker = r[["NextMarker"]] + ) } #' @rdname functions #' @export list_function_versions <- function(name, marker, n, ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name, "/versions") - query <- list() - if (!missing(marker)) { - query[["Marker"]] <- marker - } - if (!missing(n)) { - query[["MaxItems"]] <- n - } - r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) - structure(lapply(r[["Versions"]], `class<-`, "aws_lambda_function"), - marker = r[["NextMarker"]]) + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name, "/versions") + query <- list() + if (!missing(marker)) { + query[["Marker"]] <- marker + } + if (!missing(n)) { + query[["MaxItems"]] <- n + } + r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) + structure( + lapply(r[["Versions"]], `class<-`, "aws_lambda_function"), + marker = r[["NextMarker"]] + ) } #' @rdname functions #' @export delete_function <- function(name, qualifier, ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name, "/aliases/", name) - query <- list() - if (!missing(qualifier)) { - query[["Qualifier"]] <- qualifier - } - r <- lambdaHTTP(verb = "DELETE", action = act, query = query, ...) - return(TRUE) + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name) + query <- list() + if (!missing(qualifier)) { + query[["Qualifier"]] <- qualifier + } + r <- lambdaHTTP(verb = "DELETE", action = act, query = query, ...) + return(TRUE) } #' @rdname functions #' @export get_function_policy <- function(name, qualifier, ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name, "/policy") - query <- list() - if (!missing(qualifier)) { - query[["Qualifier"]] <- qualifier - } - r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) - return(r) + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name, "/policy") + query <- list() + if (!missing(qualifier)) { + query[["Qualifier"]] <- qualifier + } + r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) + return(r) } From a6dcbce384ac6bee41d2fc1e100d139b649685f3 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Tue, 14 Apr 2020 12:26:14 -0500 Subject: [PATCH 06/14] Verified account.R --- R/account.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/account.R b/R/account.R index 8cfba04..56d09e9 100644 --- a/R/account.R +++ b/R/account.R @@ -8,6 +8,6 @@ #' } #' @export get_lambda_account <- function(...) { - act <- paste0("/2016-08-19/account-settings") - lambdaHTTP(verb = "GET", action = act, ...) + act <- paste0("/2016-08-19/account-settings") + lambdaHTTP(verb = "GET", action = act, ...) } From e861cd8f363d15bfe0b69c2b7555ccea2fc5949b Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Tue, 14 Apr 2020 12:32:49 -0500 Subject: [PATCH 07/14] Update GPL-2 to GPL-3 Also cleaned DESCRIPTION. --- .Rbuildignore | 1 + DESCRIPTION | 8 +- LICENSE.md | 595 +++++++++++++++++++++++++++++++++++++++++++++++ NEWS.md | 1 + man/functions.Rd | 18 +- 5 files changed, 616 insertions(+), 7 deletions(-) create mode 100644 LICENSE.md diff --git a/.Rbuildignore b/.Rbuildignore index db5a37d..966f78a 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,4 @@ knitreadme.sh ^.*\.Rproj$ ^\.Rproj\.user$ ^\.github.? +^LICENSE\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index 31b13e0..24d9b78 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,8 +10,12 @@ Authors@R: c( email = "jonthegeek@gmail.com", comment = c(ORCID = "0000-0003-4781-4346")) ) -Description: A simple client package for the Amazon Web Services ('AWS') Lambda 'API' . -License: GPL (>= 2) +Description: A simple client package for the Amazon Web Services ('AWS') Lambda + 'API' . +Encoding: UTF-8 +LazyData: true +Depends: R (>= 3.4) +License: GPL-3 Imports: utils, httr, diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..eff38f1 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,595 @@ +GNU General Public License +========================== + +_Version 3, 29 June 2007_ +_Copyright © 2007 Free Software Foundation, Inc. <>_ + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +## Preamble + +The GNU General Public License is a free, copyleft license for software and other +kinds of works. + +The licenses for most software and other practical works are designed to take away +your freedom to share and change the works. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change all versions of a +program--to make sure it remains free software for all its users. We, the Free +Software Foundation, use the GNU General Public License for most of our software; it +applies also to any other work released this way by its authors. You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General +Public Licenses are designed to make sure that you have the freedom to distribute +copies of free software (and charge for them if you wish), that you receive source +code or can get it if you want it, that you can change the software or use pieces of +it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or +asking you to surrender the rights. Therefore, you have certain responsibilities if +you distribute copies of the software, or if you modify it: responsibilities to +respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, +you must pass on to the recipients the same freedoms that you received. You must make +sure that they, too, receive or can get the source code. And you must show them these +terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: **(1)** assert +copyright on the software, and **(2)** offer you this License giving you legal permission +to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is +no warranty for this free software. For both users' and authors' sake, the GPL +requires that modified versions be marked as changed, so that their problems will not +be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of +the software inside them, although the manufacturer can do so. This is fundamentally +incompatible with the aim of protecting users' freedom to change the software. The +systematic pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we have designed +this version of the GPL to prohibit the practice for those products. If such problems +arise substantially in other domains, we stand ready to extend this provision to +those domains in future versions of the GPL, as needed to protect the freedom of +users. + +Finally, every program is threatened constantly by software patents. States should +not allow patents to restrict development and use of software on general-purpose +computers, but in those that do, we wish to avoid the special danger that patents +applied to a free program could make it effectively proprietary. To prevent this, the +GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +## TERMS AND CONDITIONS + +### 0. Definitions + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this +License. Each licensee is addressed as “you”. “Licensees” and +“recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in +a fashion requiring copyright permission, other than the making of an exact copy. The +resulting work is called a “modified version” of the earlier work or a +work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on +the Program. + +To “propagate” a work means to do anything with it that, without +permission, would make you directly or secondarily liable for infringement under +applicable copyright law, except executing it on a computer or modifying a private +copy. Propagation includes copying, distribution (with or without modification), +making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through a computer +network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the +extent that it includes a convenient and prominently visible feature that **(1)** +displays an appropriate copyright notice, and **(2)** tells the user that there is no +warranty for the work (except to the extent that warranties are provided), that +licensees may convey the work under this License, and how to view a copy of this +License. If the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +### 1. Source Code + +The “source code” for a work means the preferred form of the work for +making modifications to it. “Object code” means any non-source form of a +work. + +A “Standard Interface” means an interface that either is an official +standard defined by a recognized standards body, or, in the case of interfaces +specified for a particular programming language, one that is widely used among +developers working in that language. + +The “System Libraries” of an executable work include anything, other than +the work as a whole, that **(a)** is included in the normal form of packaging a Major +Component, but which is not part of that Major Component, and **(b)** serves only to +enable use of the work with that Major Component, or to implement a Standard +Interface for which an implementation is available to the public in source code form. +A “Major Component”, in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system (if any) on which +the executable work runs, or a compiler used to produce the work, or an object code +interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the +source code needed to generate, install, and (for an executable work) run the object +code and to modify the work, including scripts to control those activities. However, +it does not include the work's System Libraries, or general-purpose tools or +generally available free programs which are used unmodified in performing those +activities but which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for the work, and +the source code for shared libraries and dynamically linked subprograms that the work +is specifically designed to require, such as by intimate data communication or +control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate +automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +### 2. Basic Permissions + +All rights granted under this License are granted for the term of copyright on the +Program, and are irrevocable provided the stated conditions are met. This License +explicitly affirms your unlimited permission to run the unmodified Program. The +output from running a covered work is covered by this License only if the output, +given its content, constitutes a covered work. This License acknowledges your rights +of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without +conditions so long as your license otherwise remains in force. You may convey covered +works to others for the sole purpose of having them make modifications exclusively +for you, or provide you with facilities for running those works, provided that you +comply with the terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for you must do so +exclusively on your behalf, under your direction and control, on terms that prohibit +them from making any copies of your copyrighted material outside their relationship +with you. + +Conveying under any other circumstances is permitted solely under the conditions +stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +### 3. Protecting Users' Legal Rights From Anti-Circumvention Law + +No covered work shall be deemed part of an effective technological measure under any +applicable law fulfilling obligations under article 11 of the WIPO copyright treaty +adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention +of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of +technological measures to the extent such circumvention is effected by exercising +rights under this License with respect to the covered work, and you disclaim any +intention to limit operation or modification of the work as a means of enforcing, +against the work's users, your or third parties' legal rights to forbid circumvention +of technological measures. + +### 4. Conveying Verbatim Copies + +You may convey verbatim copies of the Program's source code as you receive it, in any +medium, provided that you conspicuously and appropriately publish on each copy an +appropriate copyright notice; keep intact all notices stating that this License and +any non-permissive terms added in accord with section 7 apply to the code; keep +intact all notices of the absence of any warranty; and give all recipients a copy of +this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer +support or warranty protection for a fee. + +### 5. Conveying Modified Source Versions + +You may convey a work based on the Program, or the modifications to produce it from +the Program, in the form of source code under the terms of section 4, provided that +you also meet all of these conditions: + +* **a)** The work must carry prominent notices stating that you modified it, and giving a +relevant date. +* **b)** The work must carry prominent notices stating that it is released under this +License and any conditions added under section 7. This requirement modifies the +requirement in section 4 to “keep intact all notices”. +* **c)** You must license the entire work, as a whole, under this License to anyone who +comes into possession of a copy. This License will therefore apply, along with any +applicable section 7 additional terms, to the whole of the work, and all its parts, +regardless of how they are packaged. This License gives no permission to license the +work in any other way, but it does not invalidate such permission if you have +separately received it. +* **d)** If the work has interactive user interfaces, each must display Appropriate Legal +Notices; however, if the Program has interactive interfaces that do not display +Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are +not by their nature extensions of the covered work, and which are not combined with +it such as to form a larger program, in or on a volume of a storage or distribution +medium, is called an “aggregate” if the compilation and its resulting +copyright are not used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work in an aggregate +does not cause this License to apply to the other parts of the aggregate. + +### 6. Conveying Non-Source Forms + +You may convey a covered work in object code form under the terms of sections 4 and +5, provided that you also convey the machine-readable Corresponding Source under the +terms of this License, in one of these ways: + +* **a)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by the Corresponding Source fixed on a +durable physical medium customarily used for software interchange. +* **b)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by a written offer, valid for at least +three years and valid for as long as you offer spare parts or customer support for +that product model, to give anyone who possesses the object code either **(1)** a copy of +the Corresponding Source for all the software in the product that is covered by this +License, on a durable physical medium customarily used for software interchange, for +a price no more than your reasonable cost of physically performing this conveying of +source, or **(2)** access to copy the Corresponding Source from a network server at no +charge. +* **c)** Convey individual copies of the object code with a copy of the written offer to +provide the Corresponding Source. This alternative is allowed only occasionally and +noncommercially, and only if you received the object code with such an offer, in +accord with subsection 6b. +* **d)** Convey the object code by offering access from a designated place (gratis or for +a charge), and offer equivalent access to the Corresponding Source in the same way +through the same place at no further charge. You need not require recipients to copy +the Corresponding Source along with the object code. If the place to copy the object +code is a network server, the Corresponding Source may be on a different server +(operated by you or a third party) that supports equivalent copying facilities, +provided you maintain clear directions next to the object code saying where to find +the Corresponding Source. Regardless of what server hosts the Corresponding Source, +you remain obligated to ensure that it is available for as long as needed to satisfy +these requirements. +* **e)** Convey the object code using peer-to-peer transmission, provided you inform +other peers where the object code and Corresponding Source of the work are being +offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the +Corresponding Source as a System Library, need not be included in conveying the +object code work. + +A “User Product” is either **(1)** a “consumer product”, which +means any tangible personal property which is normally used for personal, family, or +household purposes, or **(2)** anything designed or sold for incorporation into a +dwelling. In determining whether a product is a consumer product, doubtful cases +shall be resolved in favor of coverage. For a particular product received by a +particular user, “normally used” refers to a typical or common use of +that class of product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected to use, the +product. A product is a consumer product regardless of whether the product has +substantial commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, +procedures, authorization keys, or other information required to install and execute +modified versions of a covered work in that User Product from a modified version of +its Corresponding Source. The information must suffice to ensure that the continued +functioning of the modified object code is in no case prevented or interfered with +solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for +use in, a User Product, and the conveying occurs as part of a transaction in which +the right of possession and use of the User Product is transferred to the recipient +in perpetuity or for a fixed term (regardless of how the transaction is +characterized), the Corresponding Source conveyed under this section must be +accompanied by the Installation Information. But this requirement does not apply if +neither you nor any third party retains the ability to install modified object code +on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to +continue to provide support service, warranty, or updates for a work that has been +modified or installed by the recipient, or for the User Product in which it has been +modified or installed. Access to a network may be denied when the modification itself +materially and adversely affects the operation of the network or violates the rules +and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with +this section must be in a format that is publicly documented (and with an +implementation available to the public in source code form), and must require no +special password or key for unpacking, reading or copying. + +### 7. Additional Terms + +“Additional permissions” are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. Additional +permissions that are applicable to the entire Program shall be treated as though they +were included in this License, to the extent that they are valid under applicable +law. If additional permissions apply only to part of the Program, that part may be +used separately under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any +additional permissions from that copy, or from any part of it. (Additional +permissions may be written to require their own removal in certain cases when you +modify the work.) You may place additional permissions on material, added by you to a +covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a +covered work, you may (if authorized by the copyright holders of that material) +supplement the terms of this License with terms: + +* **a)** Disclaiming warranty or limiting liability differently from the terms of +sections 15 and 16 of this License; or +* **b)** Requiring preservation of specified reasonable legal notices or author +attributions in that material or in the Appropriate Legal Notices displayed by works +containing it; or +* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that +modified versions of such material be marked in reasonable ways as different from the +original version; or +* **d)** Limiting the use for publicity purposes of names of licensors or authors of the +material; or +* **e)** Declining to grant rights under trademark law for use of some trade names, +trademarks, or service marks; or +* **f)** Requiring indemnification of licensors and authors of that material by anyone +who conveys the material (or modified versions of it) with contractual assumptions of +liability to the recipient, for any liability that these contractual assumptions +directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further +restrictions” within the meaning of section 10. If the Program as you received +it, or any part of it, contains a notice stating that it is governed by this License +along with a term that is a further restriction, you may remove that term. If a +license document contains a further restriction but permits relicensing or conveying +under this License, you may add to a covered work material governed by the terms of +that license document, provided that the further restriction does not survive such +relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in +the relevant source files, a statement of the additional terms that apply to those +files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a +separately written license, or stated as exceptions; the above requirements apply +either way. + +### 8. Termination + +You may not propagate or modify a covered work except as expressly provided under +this License. Any attempt otherwise to propagate or modify it is void, and will +automatically terminate your rights under this License (including any patent licenses +granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a +particular copyright holder is reinstated **(a)** provisionally, unless and until the +copyright holder explicitly and finally terminates your license, and **(b)** permanently, +if the copyright holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently +if the copyright holder notifies you of the violation by some reasonable means, this +is the first time you have received notice of violation of this License (for any +work) from that copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of +parties who have received copies or rights from you under this License. If your +rights have been terminated and not permanently reinstated, you do not qualify to +receive new licenses for the same material under section 10. + +### 9. Acceptance Not Required for Having Copies + +You are not required to accept this License in order to receive or run a copy of the +Program. Ancillary propagation of a covered work occurring solely as a consequence of +using peer-to-peer transmission to receive a copy likewise does not require +acceptance. However, nothing other than this License grants you permission to +propagate or modify any covered work. These actions infringe copyright if you do not +accept this License. Therefore, by modifying or propagating a covered work, you +indicate your acceptance of this License to do so. + +### 10. Automatic Licensing of Downstream Recipients + +Each time you convey a covered work, the recipient automatically receives a license +from the original licensors, to run, modify and propagate that work, subject to this +License. You are not responsible for enforcing compliance by third parties with this +License. + +An “entity transaction” is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an organization, or +merging organizations. If propagation of a covered work results from an entity +transaction, each party to that transaction who receives a copy of the work also +receives whatever licenses to the work the party's predecessor in interest had or +could give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if the predecessor +has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or +affirmed under this License. For example, you may not impose a license fee, royalty, +or other charge for exercise of rights granted under this License, and you may not +initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging +that any patent claim is infringed by making, using, selling, offering for sale, or +importing the Program or any portion of it. + +### 11. Patents + +A “contributor” is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The work thus +licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or +controlled by the contributor, whether already acquired or hereafter acquired, that +would be infringed by some manner, permitted by this License, of making, using, or +selling its contributor version, but do not include claims that would be infringed +only as a consequence of further modification of the contributor version. For +purposes of this definition, “control” includes the right to grant patent +sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license +under the contributor's essential patent claims, to make, use, sell, offer for sale, +import and otherwise run, modify and propagate the contents of its contributor +version. + +In the following three paragraphs, a “patent license” is any express +agreement or commitment, however denominated, not to enforce a patent (such as an +express permission to practice a patent or covenant not to sue for patent +infringement). To “grant” such a patent license to a party means to make +such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the +Corresponding Source of the work is not available for anyone to copy, free of charge +and under the terms of this License, through a publicly available network server or +other readily accessible means, then you must either **(1)** cause the Corresponding +Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the +patent license for this particular work, or **(3)** arrange, in a manner consistent with +the requirements of this License, to extend the patent license to downstream +recipients. “Knowingly relying” means you have actual knowledge that, but +for the patent license, your conveying the covered work in a country, or your +recipient's use of the covered work in a country, would infringe one or more +identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you +convey, or propagate by procuring conveyance of, a covered work, and grant a patent +license to some of the parties receiving the covered work authorizing them to use, +propagate, modify or convey a specific copy of the covered work, then the patent +license you grant is automatically extended to all recipients of the covered work and +works based on it. + +A patent license is “discriminatory” if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on the +non-exercise of one or more of the rights that are specifically granted under this +License. You may not convey a covered work if you are a party to an arrangement with +a third party that is in the business of distributing software, under which you make +payment to the third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties who would receive +the covered work from you, a discriminatory patent license **(a)** in connection with +copies of the covered work conveyed by you (or copies made from those copies), or **(b)** +primarily for and in connection with specific products or compilations that contain +the covered work, unless you entered into that arrangement, or that patent license +was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied +license or other defenses to infringement that may otherwise be available to you +under applicable patent law. + +### 12. No Surrender of Others' Freedom + +If conditions are imposed on you (whether by court order, agreement or otherwise) +that contradict the conditions of this License, they do not excuse you from the +conditions of this License. If you cannot convey a covered work so as to satisfy +simultaneously your obligations under this License and any other pertinent +obligations, then as a consequence you may not convey it at all. For example, if you +agree to terms that obligate you to collect a royalty for further conveying from +those to whom you convey the Program, the only way you could satisfy both those terms +and this License would be to refrain entirely from conveying the Program. + +### 13. Use with the GNU Affero General Public License + +Notwithstanding any other provision of this License, you have permission to link or +combine any covered work with a work licensed under version 3 of the GNU Affero +General Public License into a single combined work, and to convey the resulting work. +The terms of this License will continue to apply to the part which is the covered +work, but the special requirements of the GNU Affero General Public License, section +13, concerning interaction through a network will apply to the combination as such. + +### 14. Revised Versions of this License + +The Free Software Foundation may publish revised and/or new versions of the GNU +General Public License from time to time. Such new versions will be similar in spirit +to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that +a certain numbered version of the GNU General Public License “or any later +version” applies to it, you have the option of following the terms and +conditions either of that numbered version or of any later version published by the +Free Software Foundation. If the Program does not specify a version number of the GNU +General Public License, you may choose any version ever published by the Free +Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU +General Public License can be used, that proxy's public statement of acceptance of a +version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no +additional obligations are imposed on any author or copyright holder as a result of +your choosing to follow a later version. + +### 15. Disclaimer of Warranty + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE +QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +### 16. Limitation of Liability + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY +COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS +PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, +INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE +OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE +WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +### 17. Interpretation of Sections 15 and 16 + +If the disclaimer of warranty and limitation of liability provided above cannot be +given local legal effect according to their terms, reviewing courts shall apply local +law that most closely approximates an absolute waiver of all civil liability in +connection with the Program, unless a warranty or assumption of liability accompanies +a copy of the Program in return for a fee. + +_END OF TERMS AND CONDITIONS_ + +## How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to +the public, the best way to achieve this is to make it free software which everyone +can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them +to the start of each source file to most effectively state the exclusion of warranty; +and each file should have at least the “copyright” line and a pointer to +where the full notice is found. + + + Copyright (C) 2020 Jon Harmon + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this +when it starts in an interactive mode: + + aws.lambda Copyright (C) 2020 Jon Harmon + This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type 'show c' for details. + +The hypothetical commands `show w` and `show c` should show the appropriate parts of +the General Public License. Of course, your program's commands might be different; +for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to +sign a “copyright disclaimer” for the program, if necessary. For more +information on this, and how to apply and follow the GNU GPL, see +<>. + +The GNU General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may consider it +more useful to permit linking proprietary applications with the library. If this is +what you want to do, use the GNU Lesser General Public License instead of this +License. But first, please read +<>. diff --git a/NEWS.md b/NEWS.md index 7045bad..55404e3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # aws.lambda 0.1.6.9000 +* Updated license to GPL-3. * New maintainer (@jonthegeek). # aws.lambda 0.1.6 diff --git a/man/functions.Rd b/man/functions.Rd index 78495ee..d4c6383 100644 --- a/man/functions.Rd +++ b/man/functions.Rd @@ -36,13 +36,21 @@ An object of class \dQuote{aws_lambda_function}. List functions, function versions, and function policies } \details{ -\code{list_functions} lists all functions. \code{get_function} retrieves a specific function and \code{get_function_versions} retrieves all versions of that function. \code{get_function_configuration} returns the configuration details used when creating or updating the function. \code{delete_function} deletes a function, if you have permission to do so. +\code{list_functions} lists all functions. \code{get_function} + retrieves a specific function and \code{get_function_versions} retrieves + all versions of that function. \code{get_function_configuration} returns + the configuration details used when creating or updating the function. + \code{delete_function} deletes a function, if you have permission to do so. } \references{ -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html}{API Reference: GetFunction} - \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListVersionsByFunction.html}{API Reference: ListVersionsByFunction} - \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html}{API Reference: ListFunctions} - \href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunctionConfiguration.html}{API Reference: GetFunctionConfiguration} +\href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html}{API +Reference: GetFunction} +\href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListVersionsByFunction.html}{API +Reference: ListVersionsByFunction} +\href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html}{API +Reference: ListFunctions} +\href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunctionConfiguration.html}{API +Reference: GetFunctionConfiguration} } \seealso{ \code{\link{create_function}}, \code{\link{update_function}} From ba2cf2bc7fa258df04f1dfb719e9cdd7029ac59d Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Tue, 14 Apr 2020 13:34:34 -0500 Subject: [PATCH 08/14] Verified aliases.R Added warning for version == $LATEST (api bug). Changed order of parameters in create and made description optional. Logged missing update options in issue #12. --- R/aliases.R | 99 +++++++++++++++++++++++++++++++++++----------------- man/alias.Rd | 30 ++++++++++------ 2 files changed, 87 insertions(+), 42 deletions(-) diff --git a/R/aliases.R b/R/aliases.R index 04b917a..a75ec94 100644 --- a/R/aliases.R +++ b/R/aliases.R @@ -3,63 +3,98 @@ #' @description List, create, update, and delete function aliases #' @template name #' @param alias A character string specifying a function alias -#' @param description Optionally, a max 256-character description of the function for your own use. +#' @param description Optionally, a max 256-character description of the +#' function for your own use. #' @param version A character string specifying a function version #' @param marker A pagination marker from a previous request. #' @param n An integer specifying the number of results to return. #' @template dots #' @return An object of class \dQuote{aws_lambda_function}. -#' @details \code{list_functions} lists all functions. \code{get_function} retrieves a specific function and \code{get_function_versions} retrieves all versions of that function. \code{get_function_configuration} returns the configuration details used when creating or updating the function. \code{delete_function} deletes a function, if you have permission to do so. +#' @details \code{list_functions} lists all functions. \code{get_function} +#' retrieves a specific function and \code{get_function_versions} retrieves +#' all versions of that function. \code{get_function_configuration} returns +#' the configuration details used when creating or updating the function. +#' \code{delete_function} deletes a function, if you have permission to do so. #' @references -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetAlias.html}{API Reference: GetAlias} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_CreateAlias.html}{API Reference: CreateAlias} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateAlias.html}{API Reference: UpdateAlias} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_DeleteAlias.html}{API Reference: DeleteAlias} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListAliases.html}{API Reference: ListAliases} +#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetAlias.html}{API +#' Reference: GetAlias} +#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_CreateAlias.html}{API +#' Reference: CreateAlias} +#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateAlias.html}{API +#' Reference: UpdateAlias} +#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_DeleteAlias.html}{API +#' Reference: DeleteAlias} +#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListAliases.html}{API +#' Reference: ListAliases} #' @seealso \code{\link{create_function}}, \code{\link{list_functions}} #' @export -create_function_alias <- function(name, alias, description, version, ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name, "/aliases") - b <- list(Description = description, FunctionVersion = version, Name = alias) - r <- lambdaHTTP(verb = "POST", action = act, body = b, ...) - return(r) +create_function_alias <- function(name, alias, version, description, ...) { + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name, "/aliases") + b <- list(FunctionVersion = version, Name = alias) + # Description is optional. + if (!missing(description)) { + b[["Description"]] <- description + } + r <- lambdaHTTP(verb = "POST", action = act, body = b, ...) + return(r) } #' @rdname alias #' @export -update_function_alias <- function(name, alias, description, version, ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name, "/aliases/", alias) - b <- list(Description = description, FunctionVersion = version) - r <- lambdaHTTP(verb = "PUT", action = act, body = b, ...) - return(r) +update_function_alias <- function(name, alias, version, description, ...) { + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name, "/aliases/", alias) + b <- list() + if (!missing(version)) { + b[["FunctionVersion"]] <- version + } + if (!missing(description)) { + b[["Description"]] <- description + } + r <- lambdaHTTP(verb = "PUT", action = act, body = b, ...) + return(r) } #' @rdname alias #' @export delete_function_alias <- function(name, alias, ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name, "/aliases/", alias) - r <- lambdaHTTP(verb = "DELETE", action = act, ...) - return(r) + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name, "/aliases/", alias) + r <- lambdaHTTP(verb = "DELETE", action = act, ...) + return(r) } #' @rdname alias #' @export get_function_alias <- function(name, alias, ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name, "/aliases/", alias) - r <- lambdaHTTP(verb = "GET", action = act, ...) - return(r) + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name, "/aliases/", alias) + r <- lambdaHTTP(verb = "GET", action = act, ...) + return(r) } #' @rdname alias #' @export list_function_aliases <- function(name, version, marker, n, ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name, "/aliases") - query <- list(FunctionVersion = version, Marker = marker, MaxItems = n) - r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) - return(r) + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name, "/aliases") + query <- list() + if (!missing(version)) { + if (version == "$LATEST") { + warning( + "The AWS API erroneously returns an empty list with version = $LATEST.", + "\n You may want to try again without specifying a version." + ) + } + query[["FunctionVersion"]] <- version + } + if (!missing(marker)) { + query[["Marker"]] <- marker + } + if (!missing(n)) { + query[["MaxItems"]] <- n + } + r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) + return(r) } diff --git a/man/alias.Rd b/man/alias.Rd index 6ed9e70..00b6d4a 100644 --- a/man/alias.Rd +++ b/man/alias.Rd @@ -8,9 +8,9 @@ \alias{list_function_aliases} \title{Alias Management} \usage{ -create_function_alias(name, alias, description, version, ...) +create_function_alias(name, alias, version, description, ...) -update_function_alias(name, alias, description, version, ...) +update_function_alias(name, alias, version, description, ...) delete_function_alias(name, alias, ...) @@ -23,10 +23,11 @@ list_function_aliases(name, version, marker, n, ...) \item{alias}{A character string specifying a function alias} -\item{description}{Optionally, a max 256-character description of the function for your own use.} - \item{version}{A character string specifying a function version} +\item{description}{Optionally, a max 256-character description of the +function for your own use.} + \item{\dots}{Additional arguments passed to \code{\link{lambdaHTTP}}.} \item{marker}{A pagination marker from a previous request.} @@ -40,14 +41,23 @@ An object of class \dQuote{aws_lambda_function}. List, create, update, and delete function aliases } \details{ -\code{list_functions} lists all functions. \code{get_function} retrieves a specific function and \code{get_function_versions} retrieves all versions of that function. \code{get_function_configuration} returns the configuration details used when creating or updating the function. \code{delete_function} deletes a function, if you have permission to do so. +\code{list_functions} lists all functions. \code{get_function} + retrieves a specific function and \code{get_function_versions} retrieves + all versions of that function. \code{get_function_configuration} returns + the configuration details used when creating or updating the function. + \code{delete_function} deletes a function, if you have permission to do so. } \references{ -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetAlias.html}{API Reference: GetAlias} - \href{http://docs.aws.amazon.com/lambda/latest/dg/API_CreateAlias.html}{API Reference: CreateAlias} - \href{http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateAlias.html}{API Reference: UpdateAlias} - \href{http://docs.aws.amazon.com/lambda/latest/dg/API_DeleteAlias.html}{API Reference: DeleteAlias} - \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListAliases.html}{API Reference: ListAliases} +\href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetAlias.html}{API +Reference: GetAlias} +\href{http://docs.aws.amazon.com/lambda/latest/dg/API_CreateAlias.html}{API +Reference: CreateAlias} +\href{http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateAlias.html}{API +Reference: UpdateAlias} +\href{http://docs.aws.amazon.com/lambda/latest/dg/API_DeleteAlias.html}{API +Reference: DeleteAlias} +\href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListAliases.html}{API +Reference: ListAliases} } \seealso{ \code{\link{create_function}}, \code{\link{list_functions}} From b3ae5017e57ff742addfb75114d168d3bc4808a4 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Tue, 14 Apr 2020 14:46:22 -0500 Subject: [PATCH 09/14] Verified http.R Started to streamline lambdaHTTP, but there's more to do in future PRs. --- R/aliases.R | 11 +- R/http.R | 226 ++++++++++++++++++++--------------------- R/utils.R | 13 +++ man/lambdaHTTP.Rd | 38 ++++--- man/op-null-default.Rd | 18 ++++ 5 files changed, 173 insertions(+), 133 deletions(-) create mode 100644 man/op-null-default.Rd diff --git a/R/aliases.R b/R/aliases.R index a75ec94..d5edf8d 100644 --- a/R/aliases.R +++ b/R/aliases.R @@ -81,12 +81,11 @@ list_function_aliases <- function(name, version, marker, n, ...) { act <- paste0("/2015-03-31/functions/", name, "/aliases") query <- list() if (!missing(version)) { - if (version == "$LATEST") { - warning( - "The AWS API erroneously returns an empty list with version = $LATEST.", - "\n You may want to try again without specifying a version." - ) - } + warning( + "The AWS API erroneously returns an empty list when version is specified", + " if you only have one alias.", + "\n You may want to try again without specifying a version." + ) query[["FunctionVersion"]] <- version } if (!missing(marker)) { diff --git a/R/http.R b/R/http.R index 0494daa..779b61c 100644 --- a/R/http.R +++ b/R/http.R @@ -1,135 +1,131 @@ #' @title Execute AWS Lambda API Request -#' @description This is the workhorse function to execute calls to the Lambda API. +#' @description This is the workhorse function to execute calls to the Lambda +#' API. #' @param verb A character string specifying the HTTP verb to use. #' @param action A character string specifying the API version and endpoint. -#' @param query An optional named list containing query string parameters and their character values. +#' @param query An optional named list containing query string parameters and +#' their character values. #' @param headers A list of headers to pass to the HTTP request. #' @param body The HTTP request body. -#' @param verbose A logical indicating whether to be verbose. Default is given by \code{options("verbose")}. -#' @param region A character string specifying an AWS region. See \code{\link[aws.signature]{locate_credentials}}. -#' @param key A character string specifying an AWS Access Key. See \code{\link[aws.signature]{locate_credentials}}. -#' @param secret A character string specifying an AWS Secret Key. See \code{\link[aws.signature]{locate_credentials}}. -#' @param session_token Optionally, a character string specifying an AWS temporary Session Token to use in signing a request. See \code{\link[aws.signature]{locate_credentials}}. -#' @param \dots Additional arguments passed to \code{\link[httr]{GET}} or another httr request function. -#' @return If successful, a named list. Otherwise, a data structure of class \dQuote{aws-error} containing any error message(s) from AWS and information about the request attempt. -#' @details This function constructs and signs an AWS Lambda API request and returns the results thereof, or relevant debugging information in the case of error. +#' @param verbose A logical indicating whether to be verbose. Default is given +#' by \code{options("verbose")}. +#' @param region A character string specifying an AWS region. See +#' \code{\link[aws.signature]{locate_credentials}}. +#' @param key A character string specifying an AWS Access Key. See +#' \code{\link[aws.signature]{locate_credentials}}. +#' @param secret A character string specifying an AWS Secret Key. See +#' \code{\link[aws.signature]{locate_credentials}}. +#' @param session_token Optionally, a character string specifying an AWS +#' temporary Session Token to use in signing a request. See +#' \code{\link[aws.signature]{locate_credentials}}. +#' @param \dots Additional arguments passed to \code{\link[httr]{GET}} or +#' another httr request function. +#' @return If successful, a named list. Otherwise, a data structure of class +#' \dQuote{aws-error} containing any error message(s) from AWS and information +#' about the request attempt. +#' @details This function constructs and signs an AWS Lambda API request and +#' returns the results thereof, or relevant debugging information in the case +#' of error. #' @author Thomas J. Leeper -#' @seealso \code{\link{get_lambda_account}}, which works well as a hello world for the package +#' @seealso \code{\link{get_lambda_account}}, which works well as a hello world +#' for the package #' @import httr #' @importFrom utils str #' @importFrom jsonlite fromJSON toJSON #' @importFrom aws.signature signature_v4_auth locate_credentials #' @export -lambdaHTTP <- -function( - verb = "GET", - action, - query = list(), - headers = list(), - body = NULL, - verbose = getOption("verbose", FALSE), - region = Sys.getenv("AWS_DEFAULT_REGION", "us-east-1"), - key = NULL, - secret = NULL, - session_token = NULL, - ... -) { - # locate and validate credentials - credentials <- aws.signature::locate_credentials(key = key, secret = secret, session_token = session_token, region = region, verbose = verbose) - key <- credentials[["key"]] - secret <- credentials[["secret"]] - session_token <- credentials[["session_token"]] - region <- credentials[["region"]] +lambdaHTTP <- function(verb = "GET", + action, + query = NULL, + headers = list(), + body = NULL, + verbose = getOption("verbose", FALSE), + region = Sys.getenv("AWS_DEFAULT_REGION", "us-east-1"), + key = NULL, + secret = NULL, + session_token = NULL, + ...) { + # locate and validate credentials + credentials <- aws.signature::locate_credentials( + key = key, secret = secret, session_token = session_token, + region = region, verbose = verbose + ) + key <- credentials[["key"]] + secret <- credentials[["secret"]] + session_token <- credentials[["session_token"]] + region <- credentials[["region"]] - # generate request signature - d_timestamp <- format(Sys.time(), "%Y%m%dT%H%M%SZ", tz = "UTC") - url <- paste0("https://lambda.", region, ".amazonaws.com", action) + # generate request signature + d_timestamp <- format(Sys.time(), "%Y%m%dT%H%M%SZ", tz = "UTC") + url <- paste0("https://lambda.", region, ".amazonaws.com", action) - if (length(body)) { - if (is.list(body)) { - body <- jsonlite::toJSON(body, auto_unbox = TRUE) - } - } else { - body <- NULL + if (length(body)) { + if (is.list(body)) { + body <- jsonlite::toJSON(body, auto_unbox = TRUE) } + } else { + body <- NULL + } - headers[["host"]] <- paste0("lambda.",region,".amazonaws.com") - headers[["x-amz-date"]] <- d_timestamp - Sig <- signature_v4_auth( - datetime = d_timestamp, - region = region, - service = "lambda", - verb = verb, - action = action, - query_args = if (length(query)) query else NULL, - canonical_headers = if (length(headers)) headers else NULL, - request_body = if (is.null(body)) "" else body, - key = key, - secret = secret, - session_token = session_token, - verbose = verbose) - headers[["x-amz-content-sha256"]] <- Sig$BodyHash - headers[["Authorization"]] <- Sig[["SignatureHeader"]] - if (!is.null(session_token) && session_token != "") { - headers[["x-amz-security-token"]] <- session_token - } - H <- do.call("add_headers", headers) + query <- if (length(query)) query else NULL + + headers[["host"]] <- paste0("lambda.", region, ".amazonaws.com") + headers[["x-amz-date"]] <- d_timestamp + Sig <- aws.signature::signature_v4_auth( + datetime = d_timestamp, + region = region, + service = "lambda", + verb = verb, + action = action, + query_args = query, + canonical_headers = headers, + request_body = body %||% "", + key = key, + secret = secret, + session_token = session_token, + verbose = verbose + ) + headers[["x-amz-content-sha256"]] <- Sig$BodyHash + headers[["Authorization"]] <- Sig[["SignatureHeader"]] + if (!is.null(session_token) && session_token != "") { + headers[["x-amz-security-token"]] <- session_token + } + H <- do.call(httr::add_headers, headers) - # execute request - if (verb == "GET") { - if (length(query)) { - r <- GET(url, H, query = query, ...) - } else { - r <- GET(url, H, ...) - } - } else if (verb == "DELETE") { - if (length(query)) { - r <- DELETE(url, H, query = query, ...) - } else { - r <- DELETE(url, H, ...) - } - } else if (verb == "PUT") { - if (length(query)) { - if (is.null(body)) { - r <- PUT(url, H, query = query, ...) - } else { - r <- PUT(url, H, query = query, body = body, encode = "json", ...) - } - } else { - if (is.null(body)) { - r <- PUT(url, H, ...) - } else { - r <- PUT(url, H, body = body, encode = "json", ...) - } - } - } else if (verb == "POST") { - if (length(query)) { - if (is.null(body)) { - r <- POST(url, H, query = query, ...) - } else { - r <- POST(url, H, query = query, body = body, encode = "json", ...) - } - } else { - if (is.null(body)) { - r <- POST(url, H, ...) - } else { - r <- POST(url, H, body = body, encode = "json", ...) - } - } + # execute request + if (verb == "GET") { + r <- httr::GET(url, H, query = query, ...) + } else if (verb == "DELETE") { + r <- httr::DELETE(url, H, query = query, ...) + } else if (verb == "PUT") { + if (is.null(body)) { + r <- httr::PUT(url, H, query = query, ...) + } else { + r <- httr::PUT(url, H, query = query, body = body, encode = "json", ...) + } + } else if (verb == "POST") { + if (is.null(body)) { + r <- httr::POST(url, H, query = query, ...) + } else { + r <- httr::POST(url, H, query = query, body = body, encode = "json", ...) } + } - if (http_error(r)) { - h <- headers(r) - content <- try(content(r, "parsed", encoding = "UTF-8"), silent = TRUE) - if (!inherits(content, "try-error")) { - r[["content"]] <- content - } - out <- structure(r, headers = h, class = "aws_error") - attr(out, "request_canonical") <- Sig$CanonicalRequest - attr(out, "request_string_to_sign") <- Sig$StringToSign - attr(out, "request_signature") <- Sig$SignatureHeader - print(out) - stop_for_status(r) + if (httr::http_error(r)) { + h <- httr::headers(r) + content <- try( + httr::content(r, "parsed", encoding = "UTF-8"), + silent = TRUE + ) + if (!inherits(content, "try-error")) { + r[["content"]] <- content } - content(r, "parsed", encoding = "UTF-8") + out <- structure(r, headers = h, class = "aws_error") + attr(out, "request_canonical") <- Sig$CanonicalRequest + attr(out, "request_string_to_sign") <- Sig$StringToSign + attr(out, "request_signature") <- Sig$SignatureHeader + print(out) + httr::stop_for_status(r) + } + httr::content(r, "parsed", encoding = "UTF-8") } diff --git a/R/utils.R b/R/utils.R index b06a981..8087f34 100644 --- a/R/utils.R +++ b/R/utils.R @@ -24,3 +24,16 @@ get_function_name.character <- function(x, ...) { get_function_name.aws_lambda_function <- function(x, ...) { x[["FunctionName"]] } + +#' Default value for `NULL` +#' +#' This infix function makes it easy to replace `NULL`s with a default +#' value. It's inspired by the way that Ruby's or operation (`||`) +#' works. Copied from the rlang package. +#' +#' @param x,y If `x` is NULL, will return `y`; otherwise returns `x`. +#' @keywords internal +#' @name op-null-default +`%||%` <- function(x, y) { + if (is.null(x)) y else x +} diff --git a/man/lambdaHTTP.Rd b/man/lambdaHTTP.Rd index 5d52dd3..4f4ab35 100644 --- a/man/lambdaHTTP.Rd +++ b/man/lambdaHTTP.Rd @@ -7,7 +7,7 @@ lambdaHTTP( verb = "GET", action, - query = list(), + query = NULL, headers = list(), body = NULL, verbose = getOption("verbose", FALSE), @@ -23,35 +23,49 @@ lambdaHTTP( \item{action}{A character string specifying the API version and endpoint.} -\item{query}{An optional named list containing query string parameters and their character values.} +\item{query}{An optional named list containing query string parameters and +their character values.} \item{headers}{A list of headers to pass to the HTTP request.} \item{body}{The HTTP request body.} -\item{verbose}{A logical indicating whether to be verbose. Default is given by \code{options("verbose")}.} +\item{verbose}{A logical indicating whether to be verbose. Default is given +by \code{options("verbose")}.} -\item{region}{A character string specifying an AWS region. See \code{\link[aws.signature]{locate_credentials}}.} +\item{region}{A character string specifying an AWS region. See +\code{\link[aws.signature]{locate_credentials}}.} -\item{key}{A character string specifying an AWS Access Key. See \code{\link[aws.signature]{locate_credentials}}.} +\item{key}{A character string specifying an AWS Access Key. See +\code{\link[aws.signature]{locate_credentials}}.} -\item{secret}{A character string specifying an AWS Secret Key. See \code{\link[aws.signature]{locate_credentials}}.} +\item{secret}{A character string specifying an AWS Secret Key. See +\code{\link[aws.signature]{locate_credentials}}.} -\item{session_token}{Optionally, a character string specifying an AWS temporary Session Token to use in signing a request. See \code{\link[aws.signature]{locate_credentials}}.} +\item{session_token}{Optionally, a character string specifying an AWS +temporary Session Token to use in signing a request. See +\code{\link[aws.signature]{locate_credentials}}.} -\item{\dots}{Additional arguments passed to \code{\link[httr]{GET}} or another httr request function.} +\item{\dots}{Additional arguments passed to \code{\link[httr]{GET}} or +another httr request function.} } \value{ -If successful, a named list. Otherwise, a data structure of class \dQuote{aws-error} containing any error message(s) from AWS and information about the request attempt. +If successful, a named list. Otherwise, a data structure of class + \dQuote{aws-error} containing any error message(s) from AWS and information + about the request attempt. } \description{ -This is the workhorse function to execute calls to the Lambda API. +This is the workhorse function to execute calls to the Lambda + API. } \details{ -This function constructs and signs an AWS Lambda API request and returns the results thereof, or relevant debugging information in the case of error. +This function constructs and signs an AWS Lambda API request and + returns the results thereof, or relevant debugging information in the case + of error. } \seealso{ -\code{\link{get_lambda_account}}, which works well as a hello world for the package +\code{\link{get_lambda_account}}, which works well as a hello world + for the package } \author{ Thomas J. Leeper diff --git a/man/op-null-default.Rd b/man/op-null-default.Rd new file mode 100644 index 0000000..f1ea964 --- /dev/null +++ b/man/op-null-default.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{op-null-default} +\alias{op-null-default} +\alias{\%||\%} +\title{Default value for `NULL`} +\usage{ +x \%||\% y +} +\arguments{ +\item{x, y}{If `x` is NULL, will return `y`; otherwise returns `x`.} +} +\description{ +This infix function makes it easy to replace `NULL`s with a default +value. It's inspired by the way that Ruby's or operation (`||`) +works. Copied from the rlang package. +} +\keyword{internal} From f72ae0a0880c48e222a2d468c0e1e7c0df72af6e Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Tue, 14 Apr 2020 15:13:46 -0500 Subject: [PATCH 10/14] Verified invoke_function There are some issues here (logged), but no show stoppers. --- NAMESPACE | 12 ++++++--- R/http.R | 8 +++--- R/invoke.R | 56 +++++++++++++++++++++++++----------------- man/invoke_function.Rd | 7 ++++-- 4 files changed, 51 insertions(+), 32 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index a88ab28..4807158 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,11 +19,17 @@ export(list_functions) export(make_function_version) export(update_function) export(update_function_alias) -import(httr) importFrom(aws.signature,locate_credentials) importFrom(aws.signature,signature_v4_auth) importFrom(base64enc,base64encode) -importFrom(jsonlite,fromJSON) +importFrom(httr,DELETE) +importFrom(httr,GET) +importFrom(httr,POST) +importFrom(httr,PUT) +importFrom(httr,add_headers) +importFrom(httr,content) +importFrom(httr,headers) +importFrom(httr,http_error) +importFrom(httr,stop_for_status) importFrom(jsonlite,toJSON) -importFrom(utils,str) importFrom(utils,zip) diff --git a/R/http.R b/R/http.R index 779b61c..e1a0eaf 100644 --- a/R/http.R +++ b/R/http.R @@ -29,10 +29,10 @@ #' @author Thomas J. Leeper #' @seealso \code{\link{get_lambda_account}}, which works well as a hello world #' for the package -#' @import httr -#' @importFrom utils str -#' @importFrom jsonlite fromJSON toJSON -#' @importFrom aws.signature signature_v4_auth locate_credentials +#' @importFrom httr GET DELETE PUT POST add_headers http_error headers +#' stop_for_status content +#' @importFrom aws.signature locate_credentials signature_v4_auth +#' @importFrom jsonlite toJSON #' @export lambdaHTTP <- function(verb = "GET", action, diff --git a/R/invoke.R b/R/invoke.R index c9da140..4de54aa 100644 --- a/R/invoke.R +++ b/R/invoke.R @@ -2,30 +2,40 @@ #' @description Invoke a lambda function #' @template name #' @template qualifier -#' @param payload Optionally, the JSON body to send to the function. -#' @param type A character string specifying one of: (1) \dQuote{Event} (asynchronous execution), (2) \dQuote{RequestResponse} (the default), or (3) \dQuote{DryRun} to test the function without executing it. +#' @param payload Optionally, a list of parameters to send in the JSON body to +#' the function. +#' @param type A character string specifying one of: (1) \dQuote{Event} +#' (asynchronous execution), (2) \dQuote{RequestResponse} (the default), or +#' (3) \dQuote{DryRun} to test the function without executing it. #' @param log A character string to control log response. #' @template dots -#' @seealso \code{\link{create_function}}, \code{\link{list_functions}}, +#' @seealso \code{\link{create_function}}, \code{\link{list_functions}}, #' @export -invoke_function <- -function(name, qualifier, payload = NULL, - type = c("RequestResponse", "Event", "DryRun"), - log = c("None", "Tail"), - #context, - ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name, "/invocations") - query <- list() - if (!missing(qualifier)) { - query[["Qualifier"]] <- qualifier - } - h <- list("X-Amz-Invocation-Type" = match.arg(type), - "X-Amz-Log-Type" = match.arg(log))#, - #"X-Amz-Client-Context" = context) - r <- lambdaHTTP(verb = "POST", action = act, - headers = h, - query = query, - body = payload, ...) - return(r) +invoke_function <- function(name, + qualifier, + payload = NULL, + type = c("RequestResponse", "Event", "DryRun"), + log = c("None", "Tail"), + # context, + ...) { + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name, "/invocations") + query <- list() + if (!missing(qualifier)) { + query[["Qualifier"]] <- qualifier + } + h <- list( + "X-Amz-Invocation-Type" = match.arg(type), + "X-Amz-Log-Type" = match.arg(log) # , + # "X-Amz-Client-Context" = context + ) + r <- lambdaHTTP( + verb = "POST", + action = act, + headers = h, + query = query, + body = payload, + ... + ) + return(r) } diff --git a/man/invoke_function.Rd b/man/invoke_function.Rd index 18cb22c..0078802 100644 --- a/man/invoke_function.Rd +++ b/man/invoke_function.Rd @@ -18,9 +18,12 @@ invoke_function( \item{qualifier}{Optionally, either a function version or alias. If omitted, information about the latest version is returned.} -\item{payload}{Optionally, the JSON body to send to the function.} +\item{payload}{Optionally, a list of parameters to send in the JSON body to +the function.} -\item{type}{A character string specifying one of: (1) \dQuote{Event} (asynchronous execution), (2) \dQuote{RequestResponse} (the default), or (3) \dQuote{DryRun} to test the function without executing it.} +\item{type}{A character string specifying one of: (1) \dQuote{Event} +(asynchronous execution), (2) \dQuote{RequestResponse} (the default), or +(3) \dQuote{DryRun} to test the function without executing it.} \item{log}{A character string to control log response.} From 48b802ec0bac72951f3412891d9cf9ef961b6b9a Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Wed, 15 Apr 2020 08:46:33 -0500 Subject: [PATCH 11/14] Verified create_function And cleaned up references in docs. --- DESCRIPTION | 2 +- NAMESPACE | 3 + R/account.R | 2 +- R/aliases.R | 25 +-- R/create_function.R | 396 +++++++++++++++++++++++++++-------------- R/functions.R | 21 +-- R/permissions.R | 20 ++- R/source_mapping.R | 39 ++-- R/utils.R | 12 +- inst/CITATION | 13 -- man/alias.Rd | 25 +-- man/create_function.Rd | 114 ++++++++---- man/functions.Rd | 21 +-- 13 files changed, 443 insertions(+), 250 deletions(-) delete mode 100644 inst/CITATION diff --git a/DESCRIPTION b/DESCRIPTION index 24d9b78..13b249e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,7 +11,7 @@ Authors@R: c( comment = c(ORCID = "0000-0003-4781-4346")) ) Description: A simple client package for the Amazon Web Services ('AWS') Lambda - 'API' . + API . Encoding: UTF-8 LazyData: true Depends: R (>= 3.4) diff --git a/NAMESPACE b/NAMESPACE index 4807158..68cbf78 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,8 +17,11 @@ export(list_function_aliases) export(list_function_versions) export(list_functions) export(make_function_version) +export(publish_function_version) export(update_function) export(update_function_alias) +export(update_function_code) +export(update_function_config) importFrom(aws.signature,locate_credentials) importFrom(aws.signature,signature_v4_auth) importFrom(base64enc,base64encode) diff --git a/R/account.R b/R/account.R index 56d09e9..9623adc 100644 --- a/R/account.R +++ b/R/account.R @@ -4,7 +4,7 @@ #' @return A list. #' @examples #' \dontrun{ -#' get_lambda_account() +#' get_lambda_account() #' } #' @export get_lambda_account <- function(...) { diff --git a/R/aliases.R b/R/aliases.R index d5edf8d..c53cba5 100644 --- a/R/aliases.R +++ b/R/aliases.R @@ -3,28 +3,31 @@ #' @description List, create, update, and delete function aliases #' @template name #' @param alias A character string specifying a function alias +#' @param version A character string specifying a function version to associate +#' with this alias. #' @param description Optionally, a max 256-character description of the #' function for your own use. -#' @param version A character string specifying a function version #' @param marker A pagination marker from a previous request. #' @param n An integer specifying the number of results to return. #' @template dots #' @return An object of class \dQuote{aws_lambda_function}. -#' @details \code{list_functions} lists all functions. \code{get_function} -#' retrieves a specific function and \code{get_function_versions} retrieves -#' all versions of that function. \code{get_function_configuration} returns -#' the configuration details used when creating or updating the function. -#' \code{delete_function} deletes a function, if you have permission to do so. +#' @details \code{create_function_alias} creates a new function alias for a +#' given version of a function. \code{update_function_alias} updates the +#' association between a function alias and the function version. +#' \code{list_function_aliases} lists all function aliases. +#' \code{get_function_alias} retrieves a specific function alias. +#' \code{delete_function_alias} deletes a function alias, but not the +#' associated function version. #' @references -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetAlias.html}{API +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_GetAlias.html}{API #' Reference: GetAlias} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_CreateAlias.html}{API +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_CreateAlias.html}{API #' Reference: CreateAlias} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateAlias.html}{API +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_UpdateAlias.html}{API #' Reference: UpdateAlias} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_DeleteAlias.html}{API +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_DeleteAlias.html}{API #' Reference: DeleteAlias} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListAliases.html}{API +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_ListAliases.html}{API #' Reference: ListAliases} #' @seealso \code{\link{create_function}}, \code{\link{list_functions}} #' @export diff --git a/R/create_function.R b/R/create_function.R index 40d68c0..8aef69b 100644 --- a/R/create_function.R +++ b/R/create_function.R @@ -1,160 +1,296 @@ #' @rdname create_function #' @title Manage AWS Lambda Functions #' @description Create, update, and version AWS Lambda functions -#' @param func Either (1) a character string containing a url-style AWS S3 bucket and object key (e.g., \code{"s3://bucketname/objectkey"}) where the object is the .zip file containing the AWS Lambda deployment package; (2) a file string pointing to a .zip containing the deployment package; or (3) a single file (e.g., a javascript file) that will be zipped and used as the deployment. The third option is merely a convenience for very simple deployment packages. +#' @param func Either (1) a character string containing a url-style AWS S3 +#' bucket and object key (e.g., \code{"s3://bucketname/objectkey"}) where the +#' object is the .zip file containing the AWS Lambda deployment package; (2) a +#' file string pointing to a .zip containing the deployment package; or (3) a +#' single file (e.g., a javascript file) that will be zipped and used as the +#' deployment. The third option is merely a convenience for very simple +#' deployment packages. #' @template name -#' @param description Optionally, a max 256-character description of the function for your own use. -#' @param handler A character string specifying the function within your code that Lambda calls to begin execution. -#' @param role A character string containing an IAM role or an object of class \dQuote{iam_role}. This is the role that is used when the function is invoked, so it must have permissions over any AWS resources needed by the function. -#' @param runtime A character string specifying the runtime environment for the function. -#' @param timeout An integer specifying the timeout for the function, in seconds. +#' @param description Optionally, a max 256-character description of the +#' function for your own use. +#' @param handler A character string specifying the function within your code +#' that Lambda calls to begin execution. +#' @param role A character string containing an IAM role or an object of class +#' \dQuote{iam_role}. This is the role that is used when the function is +#' invoked, so it must have permissions over any AWS resources needed by the +#' function. +#' @param runtime A character string specifying the runtime environment for the +#' function. +#' @param timeout An integer specifying the timeout for the function, in +#' seconds. #' @template dots #' @return A list of class \dQuote{aws_lambda_function}. -#' @details \code{create_function} creates a new function from a deployment package. \code{update_function} can, separately, update the code within a function or the configuration settings thereof. \code{make_function_version} records a function version (see \code{\link{list_function_versions}}; changes made between versioning are not recorded. +#' @details \code{create_function} creates a new function from a deployment +#' package. \code{update_function_code} updates the code within a function. +#' \code{update_function_config} updates the configuration settings of a +#' function. \code{publish_function_version} records a function version (see +#' \code{\link{list_function_versions}}; changes made between versioning are +#' not recorded. #' @references -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html}{API Reference: CreateFunction} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunction.html}{API Reference: UpdateFunction} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_PublishFunction.html}{API Reference: PublishFunction} -#' +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html}{API +#' Reference: CreateFunction} +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunctionCode.html}{API +#' Reference: UpdateFunctionCode} +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_PublishVersion.html}{API +#' Reference: PublishVersion} +#' #' @examples #' \dontrun{ -#' # 'hello world!' example code -#' hello <- system.file("templates", "helloworld.js", package = "aws.lambda") +#' # 'hello world!' example code +#' hello <- system.file("templates", "helloworld.js", package = "aws.lambda") +#' +#' # get IAM role for Lambda execution +#' library("aws.iam") +#' id <- get_caller_identity()[["Account"]] +#' # Note: This role may not work. We recommend copying the ARN of a +#' # Lambda-capable role from the console once until we're able to more +#' # smoothly integrate with aws.iam. +#' role <- paste0("arn:aws:iam::", id, ":role/lambda_basic_execution") +#' +#' lambda_func <- create_function("helloworld", +#' func = hello, +#' handler = "helloworld.handler", +#' role = role +#' ) +#' +#' # invoke function +#' invoke_function(lambda_func) #' -#' # get IAM role for Lambda execution -#' library("aws.iam") -#' id <- get_caller_identity()[["Account"]] -#' role <- paste0("arn:aws:iam::", id, ":role/lambda_basic_execution") -#' -#' func <- create_function("helloworld", func = hello, -#' handler = "helloworld.handler", -#' role = role) -#' -#' # invoke function -#' invoke_function(func) -#' -#' # delete function -#' delete_function(func) +#' # delete function +#' delete_function(lambda_func) #' } -#' @seealso \code{\link{invoke_function}}, \code{\link{create_function_alias}}, \code{\link{list_functions}}, \code{\link{delete_function}} +#' @seealso \code{\link{invoke_function}}, \code{\link{create_function_alias}}, +#' \code{\link{list_functions}}, \code{\link{delete_function}} #' @importFrom base64enc base64encode #' @importFrom utils zip #' @export -create_function <- -function(name, - description = name, - func, - handler, - role, - runtime = c("nodejs6.10", "nodejs4.3", "java8", "python2.7", "dotnetcore1.0", "nodejs4.3-edge"), - timeout = 3L, - ...) { - act <- paste0("/2015-03-31/functions") - b <- list(Code = list()) - if (grepl("^s3://", func)) { - x <- substring(func, 6, nchar(func)) - b[["Code"]][["S3Bucket"]] <- substring(x, 1, regexpr("/", x)-1L) - b[["Code"]][["S3Key"]] <- substring(x, regexpr("/", x)+1L, nchar(x)) +create_function <- function(name, + func, + handler, + role, + runtime = c( + "nodejs12.x", + "nodejs10.x", + "java11", + "java8", + "python3.8", + "python3.7", + "python3.6", + "python2.7", + "dotnetcore3.1", + "dotnetcore2.1", + "go1.x", + "ruby2.7", + "ruby2.5", + "provided" + ), + timeout = 3L, + description, + ...) { + act <- paste0("/2015-03-31/functions") + b <- list(Code = list()) + if (grepl("^s3://", func)) { + x <- substring(func, 6, nchar(func)) + b[["Code"]][["S3Bucket"]] <- substring(x, 1, regexpr("/", x) - 1L) + b[["Code"]][["S3Key"]] <- substring(x, regexpr("/", x) + 1L, nchar(x)) + } else { + if (!file.exists(func)) { + stop(sprintf("File '%s' not found!", func)) + } + if (endsWith(func, "zip")) { + b[["Code"]] <- list(ZipFile = base64enc::base64encode(func)) } else { - if (!file.exists(func)) { - stop(sprintf("File '%s' not found!", func)) - } - if (endsWith(func, "zip")) { - b[["Code"]] <- list(ZipFile = base64enc::base64encode(func)) - } else { - wd <- getwd() - on.exit(setwd(wd)) - file.copy(from = func, to = tempdir(), overwrite = TRUE) - tmp <- tempfile(fileext = ".zip") - on.exit(unlink(tmp), add = TRUE) - setwd(tempdir()) - utils::zip(zipfile = tmp, files = basename(func)) - setwd(wd) - b[["Code"]] <- list(ZipFile = base64enc::base64encode(tmp)) - } + wd <- getwd() + on.exit(setwd(wd)) + file.copy(from = func, to = tempdir(), overwrite = TRUE) + tmp <- tempfile(fileext = ".zip") + on.exit(unlink(tmp), add = TRUE) + setwd(tempdir()) + utils::zip(zipfile = tmp, files = basename(func)) + setwd(wd) + b[["Code"]] <- list(ZipFile = base64enc::base64encode(tmp)) } - b[["FunctionName"]] <- name + } + b[["FunctionName"]] <- name + b[["Handler"]] <- handler + b[["Role"]] <- role + b[["Runtime"]] <- match.arg(runtime) + if (!missing(description)) { b[["Description"]] <- description + } + if (timeout != 3) { + b[["Timeout"]] <- timeout + } + r <- lambdaHTTP(verb = "POST", action = act, body = b, ...) + structure(r, class = "aws_lambda_function") +} + +# update_function_code and update_function_config were smushed into one +# update_function, but I think that was a bad idea, so I've split them. + +#' @rdname create_function +#' @export +update_function_code <- function(name, func, ...) { + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name, "/code") + b <- list() + if (grepl("^s3://", func)) { + x <- substring(func, 6, nchar(func)) + b[["S3Bucket"]] <- substring(x, 1, regexpr("/", x) - 1L) + b[["S3Key"]] <- substring(x, regexpr("/", x) + 1L, nchar(x)) + } else { + if (!file.exists(func)) { + stop(sprintf("File '%s' not found!", func)) + } + if (endsWith(func, "zip")) { + b[["ZipFile"]] <- base64enc::base64encode(func) + } else { + wd <- getwd() + on.exit(setwd(wd)) + file.copy(from = func, to = tempdir(), overwrite = TRUE) + tmp <- tempfile(fileext = ".zip") + on.exit(unlink(tmp), add = TRUE) + setwd(tempdir()) + utils::zip(zipfile = tmp, files = basename(func)) + setwd(wd) + b[["ZipFile"]] <- base64enc::base64encode(tmp) + } + } + r <- lambdaHTTP(verb = "PUT", action = act, body = b, ...) + structure(r, class = "aws_lambda_function") +} + +#' @rdname create_function +#' @export +update_function_config <- function(name, + description, + handler, + role, + runtime = c( + "nodejs12.x", + "nodejs10.x", + "java11", + "java8", + "python3.8", + "python3.7", + "python3.6", + "python2.7", + "dotnetcore3.1", + "dotnetcore2.1", + "go1.x", + "ruby2.7", + "ruby2.5", + "provided" + ), + timeout = 3L, + ...) { + act <- paste0("/2015-03-31/functions/", name, "/configuration") + b <- list() + if (!missing(description)) { + b[["Description"]] <- description + } + if (!missing(handler)) { b[["Handler"]] <- handler + } + if (!missing(role)) { b[["Role"]] <- role + } + if (!missing(runtime)) { b[["Runtime"]] <- match.arg(runtime) - if (timeout != 3) { - b[["Timeout"]] <- timeout - } - r <- lambdaHTTP(verb = "POST", action = act, body = b, ...) - structure(r, class = "aws_lambda_function") + } + if (!missing(runtime) && timeout != 3) { + b[["Timeout"]] <- timeout + } + r <- lambdaHTTP(verb = "PUT", action = act, body = b, ...) + structure(r, class = "aws_lambda_function") } #' @rdname create_function #' @export -update_function <- -function(name, - func, - description, - handler, - role, - runtime = c("nodejs6.10", "nodejs4.3", "java8", "python2.7", "dotnetcore1.0", "nodejs4.3-edge"), - timeout = 3L, - ...) { - name <- get_function_name(name) - if (!missing(func)) { - # update code - act <- paste0("/2015-03-31/functions/", name, "/code") - b <- list() - if (grepl("^s3://", func)) { - x <- substring(func, 6, nchar(func)) - b[["S3Bucket"]] <- substring(x, 1, regexpr("/", x)-1L) - b[["S3Key"]] <- substring(x, regexpr("/", x)+1L, nchar(x)) - } else { - if (!file.exists(func)) { - stop(sprintf("File '%s' not found!", func)) - } - if (endsWith(func, "zip")) { - b[["ZipFile"]] <- base64enc::base64encode(func) - } else { - wd <- getwd() - on.exit(setwd(wd)) - file.copy(from = func, to = tempdir(), overwrite = TRUE) - tmp <- tempfile(fileext = ".zip") - on.exit(unlink(tmp), add = TRUE) - setwd(tempdir()) - utils::zip(zipfile = tmp, files = basename(func)) - setwd(wd) - b[["ZipFile"]] <- base64enc::base64encode(tmp) - } - } - } else { - act <- paste0("/2015-03-31/functions/", name, "/configuration") - b <- list() - if (!missing(description)) { - b[["Description"]] <- description - } - if (!missing(handler)) { - b[["Handler"]] <- handler - } - if (!missing(role)) { - b[["Role"]] <- role - } - if (!missing(runtime)) { - b[["Runtime"]] <- match.arg(runtime) - } - if (!missing(runtime) && timeout != 3) { - b[["Timeout"]] <- timeout - } - } - r <- lambdaHTTP(verb = "PUT", action = act, body = b, ...) - structure(r, class = "aws_lambda_function") +update_function <- function(name, + func, + description, + handler, + role, + runtime = c( + "nodejs12.x", + "nodejs10.x", + "java11", + "java8", + "python3.8", + "python3.7", + "python3.6", + "python2.7", + "dotnetcore3.1", + "dotnetcore2.1", + "go1.x", + "ruby2.7", + "ruby2.5", + "provided" + ), + timeout = 3L, + ...) { + if (!missing(func)) { + .Deprecated( + new = "update_function_code", + package = "aws.lambda", + msg = paste( + "update_function has been replaced by update_function_code and", + "update_function_config.", + "\nSince you included the func parameter, your code will be executed", + "by update_function_code.", + "\nupdate_function will be removed in a future version of this", + "package." + ) + ) + update_function_code(name, func, ...) + } else { + .Deprecated( + new = "update_function_code", + package = "aws.lambda", + msg = paste( + "update_function has been replaced by update_function_code and", + "update_function_config.", + "\nSince you did not include the func parameter,", + "your code will be executed by update_function_config.", + "\nupdate_function will be removed in a future version of this", + "package." + ) + ) + update_function_config( + name, description, handler, role, runtime, timeout, ... + ) + } +} + +#' @rdname create_function +#' @export +publish_function_version <- function(name, description, ...) { + name <- get_function_name(name) + act <- paste0("/2015-03-31/functions/", name, "/versions") + b <- list() + if (!missing(description)) { + b[["Description"]] <- description + } + r <- lambdaHTTP(verb = "POST", action = act, body = b, ...) + return(r) } #' @rdname create_function #' @export make_function_version <- function(name, description, ...) { - name <- get_function_name(name) - act <- paste0("/2015-03-31/functions/", name, "/versions") - b <- list() - if (!missing(description)) { - b[["Description"]] <- description - } - r <- lambdaHTTP(verb = "POST", action = act, body = b, ...) - return(r) + .Deprecated( + new = "publish_function_version", + package = "aws.lambda", + msg = paste( + "make_function_version has been renamed to publish_function_version", + "to better match the api.", + "\nmake_function_version will be removed in a future version", + "of this package." + ) + ) + publish_function_version(name = name, description = description, ...) } diff --git a/R/functions.R b/R/functions.R index 0b3b434..18e83c2 100644 --- a/R/functions.R +++ b/R/functions.R @@ -8,20 +8,21 @@ #' @template dots #' @return An object of class \dQuote{aws_lambda_function}. #' @details \code{list_functions} lists all functions. \code{get_function} -#' retrieves a specific function and \code{get_function_versions} retrieves -#' all versions of that function. \code{get_function_configuration} returns -#' the configuration details used when creating or updating the function. -#' \code{delete_function} deletes a function, if you have permission to do so. +#' retrieves a specific function and \code{list_function_versions} retrieves +#' all versions of that function. \code{get_function_policy} returns the +#' resource-based IAM policy for a function. \code{delete_function} deletes a +#' function, if you have permission to do so. #' @references -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html}{API +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html}{API #' Reference: GetFunction} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListVersionsByFunction.html}{API +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_ListVersionsByFunction.html}{API #' Reference: ListVersionsByFunction} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html}{API +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html}{API #' Reference: ListFunctions} -#' \href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunctionConfiguration.html}{API -#' Reference: GetFunctionConfiguration} -#' @seealso \code{\link{create_function}}, \code{\link{update_function}} +#' \href{https://docs.aws.amazon.com/lambda/latest/dg/API_GetPolicy.html}{API +#' Reference: GetPolicy} +#' @seealso \code{\link{create_function}}, \code{\link{update_function_code}}, +#' \code{\link{update_function_config}} #' @export get_function <- function(name, qualifier, ...) { name <- get_function_name(name) diff --git a/R/permissions.R b/R/permissions.R index fe6f72d..fea8227 100644 --- a/R/permissions.R +++ b/R/permissions.R @@ -1,13 +1,17 @@ +# These functions are not yet exported, and I don't think they're pointing to a +# valid endpoint (they need a date before /functions/). I'm not deleting yet, +# but I also have not verified these. + add_permission <- function(func, qualifier, ...) { - act <- paste0("/functions/", func, "/policy") - query <- list(Qualifier = qualifier) - r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) - return(r) + act <- paste0("/functions/", func, "/policy") + query <- list(Qualifier = qualifier) + r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) + return(r) } remove_permission <- function(func, qualifier, id, ...) { - act <- paste0("/functions/", func, "/policy/", id) - query <- list(Qualifier = qualifier) - r <- lambdaHTTP(verb = "DELETE", action = act, query = query, ...) - return(r) + act <- paste0("/functions/", func, "/policy/", id) + query <- list(Qualifier = qualifier) + r <- lambdaHTTP(verb = "DELETE", action = act, query = query, ...) + return(r) } diff --git a/R/source_mapping.R b/R/source_mapping.R index f07fccb..b24bb6d 100644 --- a/R/source_mapping.R +++ b/R/source_mapping.R @@ -1,30 +1,37 @@ +# The endpoints ("act") need to be updated on these before they're exported. + create_eventsource <- function(body, ...) { - act <- paste0("/event-source-mapping") - r <- lambdaHTTP(verb = "POST", action = act, body = body, ...) - return(r) + act <- paste0("/event-source-mapping") + r <- lambdaHTTP(verb = "POST", action = act, body = body, ...) + return(r) } update_eventsource <- function(source, body, ...) { - act <- paste0("/event-source-mapping/", source) - r <- lambdaHTTP(verb = "PUT", action = act, body = body, ...) - return(r) + act <- paste0("/event-source-mapping/", source) + r <- lambdaHTTP(verb = "PUT", action = act, body = body, ...) + return(r) } delete_eventsource <- function(source, ...) { - act <- paste0("/event-source-mapping/", source) - r <- lambdaHTTP(verb = "DELETE", action = act, ...) - return(r) + act <- paste0("/event-source-mapping/", source) + r <- lambdaHTTP(verb = "DELETE", action = act, ...) + return(r) } get_eventsource <- function(source, ...) { - act <- paste0("/event-source-mapping/", source) - r <- lambdaHTTP(verb = "GET", action = act, ...) - return(r) + act <- paste0("/event-source-mapping/", source) + r <- lambdaHTTP(verb = "GET", action = act, ...) + return(r) } list_eventsources <- function(stream, func, marker, n, ...) { - act <- paste0("/event-source-mappings/") - query <- list(EventSourceArn = stream, FunctionName = func, Marker = marker, MaxItems = n) - r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) - return(r) + act <- paste0("/event-source-mappings/") + query <- list( + EventSourceArn = stream, + FunctionName = func, + Marker = marker, + MaxItems = n + ) + r <- lambdaHTTP(verb = "GET", action = act, query = query, ...) + return(r) } diff --git a/R/utils.R b/R/utils.R index 8087f34..6066fac 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,6 +1,6 @@ print.aws_lambda_function <- function(x, ...) { - print(str(x)) - return(invisible(x)) + print(utils::str(x)) + return(invisible(x)) } #' @rdname get_function_name @@ -10,19 +10,19 @@ print.aws_lambda_function <- function(x, ...) { #' @param \dots Additional arguments passed to methods #' @export get_function_name <- function(x, ...) { - UseMethod("get_function_name") + UseMethod("get_function_name") } #' @rdname get_function_name #' @export get_function_name.character <- function(x, ...) { - x + x } #' @rdname get_function_name #' @export get_function_name.aws_lambda_function <- function(x, ...) { - x[["FunctionName"]] + x[["FunctionName"]] } #' Default value for `NULL` @@ -35,5 +35,5 @@ get_function_name.aws_lambda_function <- function(x, ...) { #' @keywords internal #' @name op-null-default `%||%` <- function(x, y) { - if (is.null(x)) y else x + if (is.null(x)) y else x } diff --git a/inst/CITATION b/inst/CITATION deleted file mode 100644 index 1109e79..0000000 --- a/inst/CITATION +++ /dev/null @@ -1,13 +0,0 @@ -citHeader("To cite package 'aws.lambda' in publications use:") - year <- sub(".*(2[[:digit:]]{3})-.*", "\\1", meta$Date, perl = TRUE) - vers <- paste("R package version", meta$Version) - citEntry(entry="Manual", - title = "aws.lambda: AWS Lambda Client Package", - author = personList(as.person("Thomas J. Leeper")), - year = year, - note = vers, - textVersion = - paste("Thomas J. Leeper (", - year, - "). aws.lambda: AWS Lambda Client Package. ", - vers, ".", sep="")) diff --git a/man/alias.Rd b/man/alias.Rd index 00b6d4a..4c42311 100644 --- a/man/alias.Rd +++ b/man/alias.Rd @@ -23,7 +23,8 @@ list_function_aliases(name, version, marker, n, ...) \item{alias}{A character string specifying a function alias} -\item{version}{A character string specifying a function version} +\item{version}{A character string specifying a function version to associate +with this alias.} \item{description}{Optionally, a max 256-character description of the function for your own use.} @@ -41,22 +42,24 @@ An object of class \dQuote{aws_lambda_function}. List, create, update, and delete function aliases } \details{ -\code{list_functions} lists all functions. \code{get_function} - retrieves a specific function and \code{get_function_versions} retrieves - all versions of that function. \code{get_function_configuration} returns - the configuration details used when creating or updating the function. - \code{delete_function} deletes a function, if you have permission to do so. +\code{create_function_alias} creates a new function alias for a + given version of a function. \code{update_function_alias} updates the + association between a function alias and the function version. + \code{list_function_aliases} lists all function aliases. + \code{get_function_alias} retrieves a specific function alias. + \code{delete_function_alias} deletes a function alias, but not the + associated function version. } \references{ -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetAlias.html}{API +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_GetAlias.html}{API Reference: GetAlias} -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_CreateAlias.html}{API +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_CreateAlias.html}{API Reference: CreateAlias} -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateAlias.html}{API +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_UpdateAlias.html}{API Reference: UpdateAlias} -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_DeleteAlias.html}{API +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_DeleteAlias.html}{API Reference: DeleteAlias} -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListAliases.html}{API +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_ListAliases.html}{API Reference: ListAliases} } \seealso{ diff --git a/man/create_function.Rd b/man/create_function.Rd index 8978d2e..02280a2 100644 --- a/man/create_function.Rd +++ b/man/create_function.Rd @@ -2,18 +2,36 @@ % Please edit documentation in R/create_function.R \name{create_function} \alias{create_function} +\alias{update_function_code} +\alias{update_function_config} \alias{update_function} +\alias{publish_function_version} \alias{make_function_version} \title{Manage AWS Lambda Functions} \usage{ create_function( name, - description = name, func, handler, role, - runtime = c("nodejs6.10", "nodejs4.3", "java8", "python2.7", "dotnetcore1.0", - "nodejs4.3-edge"), + runtime = c("nodejs12.x", "nodejs10.x", "java11", "java8", "python3.8", "python3.7", + "python3.6", "python2.7", "dotnetcore3.1", "dotnetcore2.1", "go1.x", "ruby2.7", + "ruby2.5", "provided"), + timeout = 3L, + description, + ... +) + +update_function_code(name, func, ...) + +update_function_config( + name, + description, + handler, + role, + runtime = c("nodejs12.x", "nodejs10.x", "java11", "java8", "python3.8", "python3.7", + "python3.6", "python2.7", "dotnetcore3.1", "dotnetcore2.1", "go1.x", "ruby2.7", + "ruby2.5", "provided"), timeout = 3L, ... ) @@ -24,28 +42,44 @@ update_function( description, handler, role, - runtime = c("nodejs6.10", "nodejs4.3", "java8", "python2.7", "dotnetcore1.0", - "nodejs4.3-edge"), + runtime = c("nodejs12.x", "nodejs10.x", "java11", "java8", "python3.8", "python3.7", + "python3.6", "python2.7", "dotnetcore3.1", "dotnetcore2.1", "go1.x", "ruby2.7", + "ruby2.5", "provided"), timeout = 3L, ... ) +publish_function_version(name, description, ...) + make_function_version(name, description, ...) } \arguments{ \item{name}{A character string specifying the function name (either a full ARN or a max 64-character string). For functions other than \code{create_function} this can also be an object of class \dQuote{aws_lambda_function}.} -\item{description}{Optionally, a max 256-character description of the function for your own use.} +\item{func}{Either (1) a character string containing a url-style AWS S3 +bucket and object key (e.g., \code{"s3://bucketname/objectkey"}) where the +object is the .zip file containing the AWS Lambda deployment package; (2) a +file string pointing to a .zip containing the deployment package; or (3) a +single file (e.g., a javascript file) that will be zipped and used as the +deployment. The third option is merely a convenience for very simple +deployment packages.} -\item{func}{Either (1) a character string containing a url-style AWS S3 bucket and object key (e.g., \code{"s3://bucketname/objectkey"}) where the object is the .zip file containing the AWS Lambda deployment package; (2) a file string pointing to a .zip containing the deployment package; or (3) a single file (e.g., a javascript file) that will be zipped and used as the deployment. The third option is merely a convenience for very simple deployment packages.} +\item{handler}{A character string specifying the function within your code +that Lambda calls to begin execution.} -\item{handler}{A character string specifying the function within your code that Lambda calls to begin execution.} +\item{role}{A character string containing an IAM role or an object of class +\dQuote{iam_role}. This is the role that is used when the function is +invoked, so it must have permissions over any AWS resources needed by the +function.} -\item{role}{A character string containing an IAM role or an object of class \dQuote{iam_role}. This is the role that is used when the function is invoked, so it must have permissions over any AWS resources needed by the function.} +\item{runtime}{A character string specifying the runtime environment for the +function.} -\item{runtime}{A character string specifying the runtime environment for the function.} +\item{timeout}{An integer specifying the timeout for the function, in +seconds.} -\item{timeout}{An integer specifying the timeout for the function, in seconds.} +\item{description}{Optionally, a max 256-character description of the +function for your own use.} \item{\dots}{Additional arguments passed to \code{\link{lambdaHTTP}}.} } @@ -56,34 +90,48 @@ A list of class \dQuote{aws_lambda_function}. Create, update, and version AWS Lambda functions } \details{ -\code{create_function} creates a new function from a deployment package. \code{update_function} can, separately, update the code within a function or the configuration settings thereof. \code{make_function_version} records a function version (see \code{\link{list_function_versions}}; changes made between versioning are not recorded. +\code{create_function} creates a new function from a deployment + package. \code{update_function_code} updates the code within a function. + \code{update_function_config} updates the configuration settings of a + function. \code{publish_function_version} records a function version (see + \code{\link{list_function_versions}}; changes made between versioning are + not recorded. } \examples{ \dontrun{ - # 'hello world!' example code - hello <- system.file("templates", "helloworld.js", package = "aws.lambda") - - # get IAM role for Lambda execution - library("aws.iam") - id <- get_caller_identity()[["Account"]] - role <- paste0("arn:aws:iam::", id, ":role/lambda_basic_execution") - - func <- create_function("helloworld", func = hello, - handler = "helloworld.handler", - role = role) - - # invoke function - invoke_function(func) - - # delete function - delete_function(func) +# 'hello world!' example code +hello <- system.file("templates", "helloworld.js", package = "aws.lambda") + +# get IAM role for Lambda execution +library("aws.iam") +id <- get_caller_identity()[["Account"]] +# Note: This role may not work. We recommend copying the ARN of a +# Lambda-capable role from the console once until we're able to more +# smoothly integrate with aws.iam. +role <- paste0("arn:aws:iam::", id, ":role/lambda_basic_execution") + +lambda_func <- create_function("helloworld", + func = hello, + handler = "helloworld.handler", + role = role +) + +# invoke function +invoke_function(lambda_func) + +# delete function +delete_function(lambda_func) } } \references{ -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html}{API Reference: CreateFunction} - \href{http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunction.html}{API Reference: UpdateFunction} - \href{http://docs.aws.amazon.com/lambda/latest/dg/API_PublishFunction.html}{API Reference: PublishFunction} +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html}{API +Reference: CreateFunction} +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunctionCode.html}{API +Reference: UpdateFunctionCode} +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_PublishVersion.html}{API +Reference: PublishVersion} } \seealso{ -\code{\link{invoke_function}}, \code{\link{create_function_alias}}, \code{\link{list_functions}}, \code{\link{delete_function}} +\code{\link{invoke_function}}, \code{\link{create_function_alias}}, + \code{\link{list_functions}}, \code{\link{delete_function}} } diff --git a/man/functions.Rd b/man/functions.Rd index d4c6383..332ad4e 100644 --- a/man/functions.Rd +++ b/man/functions.Rd @@ -37,21 +37,22 @@ List functions, function versions, and function policies } \details{ \code{list_functions} lists all functions. \code{get_function} - retrieves a specific function and \code{get_function_versions} retrieves - all versions of that function. \code{get_function_configuration} returns - the configuration details used when creating or updating the function. - \code{delete_function} deletes a function, if you have permission to do so. + retrieves a specific function and \code{list_function_versions} retrieves + all versions of that function. \code{get_function_policy} returns the + resource-based IAM policy for a function. \code{delete_function} deletes a + function, if you have permission to do so. } \references{ -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html}{API +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html}{API Reference: GetFunction} -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListVersionsByFunction.html}{API +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_ListVersionsByFunction.html}{API Reference: ListVersionsByFunction} -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html}{API +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html}{API Reference: ListFunctions} -\href{http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunctionConfiguration.html}{API -Reference: GetFunctionConfiguration} +\href{https://docs.aws.amazon.com/lambda/latest/dg/API_GetPolicy.html}{API +Reference: GetPolicy} } \seealso{ -\code{\link{create_function}}, \code{\link{update_function}} +\code{\link{create_function}}, \code{\link{update_function_code}}, + \code{\link{update_function_config}} } From d5019685b6fc3f75941a2cf71097f9ddd034cb7a Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Wed, 15 Apr 2020 09:12:48 -0500 Subject: [PATCH 12/14] Final cleanups pre-release. --- DESCRIPTION | 2 +- NEWS.md | 4 +++- man/get_lambda_account.Rd | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 13b249e..36c5fc2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: aws.lambda Type: Package Title: AWS Lambda Client Package -Version: 0.1.6.9000 +Version: 0.2.0 Authors@R: c( person("Thomas J.", "Leeper", role = c("aut"), email = "thosjleeper@gmail.com", diff --git a/NEWS.md b/NEWS.md index 55404e3..14461c1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,9 @@ # aws.lambda 0.1.6.9000 -* Updated license to GPL-3. * New maintainer (@jonthegeek). +* Updated license to GPL-3. +* Deprecated `update_function()` in favor of `update_function_code()` and `update_function_config()`. +* Deprecated `make_function_version()` in favor of `publish_function_version()`. # aws.lambda 0.1.6 diff --git a/man/get_lambda_account.Rd b/man/get_lambda_account.Rd index cd471b3..828cdd7 100644 --- a/man/get_lambda_account.Rd +++ b/man/get_lambda_account.Rd @@ -17,6 +17,6 @@ Get account settings } \examples{ \dontrun{ - get_lambda_account() +get_lambda_account() } } From d589232e5c42272efff8c165de920ff25bf6dd8d Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Wed, 15 Apr 2020 09:31:01 -0500 Subject: [PATCH 13/14] Updated README. --- .Rbuildignore | 1 + README.Rmd | 80 ++++++++++++++++++-------------- README.html | 75 ------------------------------ README.md | 125 ++++++++++++++++++++++++++------------------------ 4 files changed, 111 insertions(+), 170 deletions(-) delete mode 100644 README.html diff --git a/.Rbuildignore b/.Rbuildignore index 966f78a..c44c41b 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -11,3 +11,4 @@ knitreadme.sh ^\.Rproj\.user$ ^\.github.? ^LICENSE\.md$ +^README\.Rmd$ diff --git a/README.Rmd b/README.Rmd index 8ae22c4..0b37e1a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,12 +1,47 @@ -# AWS Lambda Client Package +--- +output: github_document +--- + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` + +# aws.lambda -**aws.lambda** is a simple client package for the [Amazon Web Services (AWS) Lambda API](https://aws.amazon.com/lambda/). + +[![CRAN status](https://www.r-pkg.org/badges/version/aws.lambda)](https://CRAN.R-project.org/package=aws.lambda) + + +**aws.lambda** is a client package for the [Amazon Web Services (AWS) Lambda API](https://aws.amazon.com/lambda/). + +## Installation + +You can install the released version of aws.lambda from [CRAN](https://CRAN.R-project.org) with: + +``` r +install.packages("aws.lambda") +``` + +And the development version from [GitHub](https://github.com/) with: + +``` r +# install.packages("remotes") +remotes::install_github("cloudyr/aws.lambda") +``` +## API Keys To use the package, you will need an AWS account and to enter your credentials into R. Your keypair can be generated on the [IAM Management Console](https://aws.amazon.com/) under the heading *Access Keys*. Note that you only have access to your secret key once. After it is generated, you need to save it in a secure location. New keypairs can be generated at any time if yours has been lost, stolen, or forgotten. The [**aws.iam** package](https://github.com/cloudyr/aws.iam) profiles tools for working with IAM, including creating roles, users, groups, and credentials programmatically; it is not needed to *use* IAM credentials. -A detailed description of how credentials can be specified is provided at: https://github.com/cloudyr/aws.signature/. The easiest way is to simply set environment variables on the command line prior to starting R or via an `Renviron.site` or `.Renviron` file, which are used to set environment variables in R during startup (see `? Startup`). They can be also set within R: +A detailed description of how credentials can be specified is provided at: https://github.com/cloudyr/aws.signature/. The easiest way is to simply set environment variables on the command line prior to starting R or via an `Renviron.site` or `.Renviron` file, which are used to set environment variables in R during startup (see `? Startup`). They can also be set within R: -```R +```{r eval=FALSE} Sys.setenv("AWS_ACCESS_KEY_ID" = "mykey", "AWS_SECRET_ACCESS_KEY" = "mysecretkey", "AWS_DEFAULT_REGION" = "us-east-1", @@ -17,7 +52,7 @@ Sys.setenv("AWS_ACCESS_KEY_ID" = "mykey", The package is still under rapid development, but a simple and literal "Hello, world!" example can be found by doing the following: -```{r} +```{r eval=FALSE} library("aws.lambda") # get list of all current functions @@ -26,7 +61,8 @@ funclist <- sapply(list_functions(), get_function_name) # 'hello world!' example code hello <- system.file("templates", "helloworld.js", package = "aws.lambda") -# get IAM role for Lambda execution +# get IAM role for Lambda execution. Note: This is not currently sufficient, and +# will be updated in an upcoming update to the package. requireNamespace("aws.iam") id <- aws.iam::get_caller_identity()[["Account"]] role <- paste0("arn:aws:iam::", id, ":role/lambda_basic_execution") @@ -42,15 +78,15 @@ if (!"helloworld" %in% funclist) { invoke_function(func) ``` -```{r, echo=FALSE, results="hide"} +```{r eval=FALSE} delete_function(func) ``` Obviously this is a trivial lambda function, but the point is that basically anything (in node.js, python, or java) could be written into the "deployment package" and called in this way. -A sligtly more complex example shows how to pass arguments to the lambda function via the function's `payload` and examine the response. +A slightly more complex example shows how to pass arguments to the lambda function via the function's `payload` and examine the response. -```{r} +```{r eval=FALSE} # example function that performs simple addition plus <- system.file("templates", "plus.js", package = "aws.lambda") @@ -72,33 +108,9 @@ invoke_function(func, payload = list(a = -5, b = 7)) ``` -```{r, echo=FALSE, results="hide"} +```{r eval=FALSE} delete_function(func) ``` -## Installation - -[![CRAN](https://www.r-pkg.org/badges/version/aws.lambda)](https://cran.r-project.org/package=aws.lambda) -![Downloads](https://cranlogs.r-pkg.org/badges/aws.lambda) -[![Build Status](https://travis-ci.org/cloudyr/aws.lambda.png?branch=master)](https://travis-ci.org/cloudyr/aws.lambda) -[![codecov.io](https://codecov.io/github/cloudyr/aws.lambda/coverage.svg?branch=master)](https://codecov.io/github/cloudyr/aws.lambda?branch=master) - -This package is not yet on CRAN. To install the latest development version you can install from the cloudyr drat repository: - -```R -# latest stable version -install.packages("aws.s3", repos = c("cloudyr" = "http://cloudyr.github.io/drat")) -``` - -To install the latest development version from GitHub, run the following: - -```R -if (!require("remotes")){ - install.packages("remotes") -} -remotes::install_github("cloudyr/aws.lambda") -``` - - --- [![cloudyr project logo](http://i.imgur.com/JHS98Y7.png)](https://github.com/cloudyr) diff --git a/README.html b/README.html deleted file mode 100644 index ada811e..0000000 --- a/README.html +++ /dev/null @@ -1,75 +0,0 @@ -

AWS Lambda Client Package

-

aws.lambda is a simple client package for the Amazon Web Services (AWS) Lambda API.

-

To use the package, you will need an AWS account and enter your credentials into R. Your keypair can be generated on the IAM Management Console under the heading Access Keys. Note that you only have access to your secret key once. After it is generated, you need to save it in a secure location. New keypairs can be generated at any time if yours has been lost, stolen, or forgotten.

-

By default, all cloudyr packages look for the access key ID and secret access key in environment variables. You can also use this to specify a default region or a temporary "session token". For example:

-
Sys.setenv("AWS_ACCESS_KEY_ID" = "mykey",
-           "AWS_SECRET_ACCESS_KEY" = "mysecretkey",
-           "AWS_DEFAULT_REGION" = "us-east-1",
-           "AWS_SESSION_TOKEN" = "mytoken")
-

These can alternatively be set on the command line prior to starting R or via an Renviron.site or .Renviron file, which are used to set environment variables in R during startup (see ? Startup).

-

If you work with multiple AWS accounts, another option that is consistent with other Amazon SDKs is to create a centralized ~/.aws/credentials file, containing credentials for multiple accounts. You can then use credentials from this file on-the-fly by simply doing:

-
# use your 'default' account credentials
-aws.signature::use_credentials()
-
-# use an alternative credentials profile
-aws.signature::use_credentials(profile = "bob")
-

Temporary session tokens are stored in environment variable AWS_SESSION_TOKEN (and will be stored there by the use_credentials() function). The aws.iam package provides an R interface to IAM roles and the generation of temporary session tokens via the security token service (STS).

-

Code Examples

-

The package is still under rapid development, but a simple and literal "Hello, world!" example can be found by doing the following:

-
library("aws.lambda")
-
-# get list of all current functions
-funclist <- sapply(list_functions(), get_function_name)
-
-# 'hello world!' example code
-hello <- system.file("templates", "helloworld.js", package = "aws.lambda")
-
-# get IAM role for Lambda execution
-requireNamespace("aws.iam")
-
## Loading required namespace: aws.iam
-
id <- aws.iam::get_caller_identity()[["Account"]]
-role <- paste0("arn:aws:iam::", id, ":role/lambda_basic_execution")
-
-if (!"helloworld" %in% funclist) {
-  func <- create_function(name = "helloworld", func = hello, 
-                          handler = "helloworld.handler", role = role)
-} else {
-  func <- get_function("helloworld")
-}
-
-# invoke function
-invoke_function(func)
-
## [1] "Hello, world!"
-

Obviously this is a trivial lambda function, but the point is that basically anything (in node.js, python, or java) could be written into the "deployment package" and called in this way. A sligtly more complex example shows how to pass arguments to the lambda function and examine the response.

-
# example function that performs addition
-plus <- system.file("templates", "plus.js", package = "aws.lambda")
-
-# get IAM role for Lambda execution
-requireNamespace("aws.iam")
-id <- aws.iam::get_caller_identity()[["Account"]]
-role <- paste0("arn:aws:iam::", id, ":role/lambda_basic_execution")
-
-if (!"plus" %in% funclist) {
-  func <- create_function(name = "plus", func = plus, 
-                          handler = "plus.handler", role = role)
-} else {
-  func <- get_function("plus")
-}
-
-# invoke function
-invoke_function(func, payload = list(a = 2, b = 3))
-
## [1] 5
-
invoke_function(func, payload = list(a = -5, b = 7))
-
## [1] 2
-

Installation

-

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.s3", repos = c("cloudyr" = "http://cloudyr.github.io/drat"))
-

To install the latest development version from GitHub, run the following:

-
if (!require("ghit")){
-    install.packages("ghit")
-}
-ghit::install_github("cloudyr/aws.lambda")
-
-

cloudyr project logo

diff --git a/README.md b/README.md index 6e91647..e4dc222 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,53 @@ -# AWS Lambda Client Package -**aws.lambda** is a simple client package for the [Amazon Web Services (AWS) Lambda API](https://aws.amazon.com/lambda/). + -To use the package, you will need an AWS account and to enter your credentials into R. Your keypair can be generated on the [IAM Management Console](https://aws.amazon.com/) under the heading *Access Keys*. Note that you only have access to your secret key once. After it is generated, you need to save it in a secure location. New keypairs can be generated at any time if yours has been lost, stolen, or forgotten. The [**aws.iam** package](https://github.com/cloudyr/aws.iam) profiles tools for working with IAM, including creating roles, users, groups, and credentials programmatically; it is not needed to *use* IAM credentials. +# aws.lambda -A detailed description of how credentials can be specified is provided at: https://github.com/cloudyr/aws.signature/. The easiest way is to simply set environment variables on the command line prior to starting R or via an `Renviron.site` or `.Renviron` file, which are used to set environment variables in R during startup (see `? Startup`). They can be also set within R: + -```R +[![CRAN +status](https://www.r-pkg.org/badges/version/aws.lambda)](https://CRAN.R-project.org/package=aws.lambda) + + +**aws.lambda** is a client package for the [Amazon Web Services (AWS) +Lambda API](https://aws.amazon.com/lambda/). + +## Installation + +You can install the released version of aws.lambda from +[CRAN](https://CRAN.R-project.org) with: + +``` r +install.packages("aws.lambda") +``` + +And the development version from [GitHub](https://github.com/) with: + +``` r +# install.packages("remotes") +remotes::install_github("cloudyr/aws.lambda") +``` + +## API Keys + +To use the package, you will need an AWS account and to enter your +credentials into R. Your keypair can be generated on the [IAM Management +Console](https://aws.amazon.com/) under the heading *Access Keys*. Note +that you only have access to your secret key once. After it is +generated, you need to save it in a secure location. New keypairs can be +generated at any time if yours has been lost, stolen, or forgotten. The +[**aws.iam** package](https://github.com/cloudyr/aws.iam) profiles tools +for working with IAM, including creating roles, users, groups, and +credentials programmatically; it is not needed to *use* IAM credentials. + +A detailed description of how credentials can be specified is provided +at: . The easiest way is to +simply set environment variables on the command line prior to starting R +or via an `Renviron.site` or `.Renviron` file, which are used to set +environment variables in R during startup (see `? Startup`). They can +also be set within R: + +``` r Sys.setenv("AWS_ACCESS_KEY_ID" = "mykey", "AWS_SECRET_ACCESS_KEY" = "mysecretkey", "AWS_DEFAULT_REGION" = "us-east-1", @@ -15,10 +56,10 @@ Sys.setenv("AWS_ACCESS_KEY_ID" = "mykey", ## Code Examples -The package is still under rapid development, but a simple and literal "Hello, world!" example can be found by doing the following: +The package is still under rapid development, but a simple and literal +“Hello, world\!” example can be found by doing the following: - -```r +``` r library("aws.lambda") # get list of all current functions @@ -27,15 +68,9 @@ funclist <- sapply(list_functions(), get_function_name) # 'hello world!' example code hello <- system.file("templates", "helloworld.js", package = "aws.lambda") -# get IAM role for Lambda execution +# get IAM role for Lambda execution. Note: This is not currently sufficient, and +# will be updated in an upcoming update to the package. requireNamespace("aws.iam") -``` - -``` -## Loading required namespace: aws.iam -``` - -```r id <- aws.iam::get_caller_identity()[["Account"]] role <- paste0("arn:aws:iam::", id, ":role/lambda_basic_execution") @@ -50,18 +85,18 @@ if (!"helloworld" %in% funclist) { invoke_function(func) ``` +``` r +delete_function(func) ``` -## [1] "Hello, world!" -``` - - -Obviously this is a trivial lambda function, but the point is that basically anything (in node.js, python, or java) could be written into the "deployment package" and called in this way. +Obviously this is a trivial lambda function, but the point is that +basically anything (in node.js, python, or java) could be written into +the “deployment package” and called in this way. -A sligtly more complex example shows how to pass arguments to the lambda function via the function's `payload` and examine the response. +A slightly more complex example shows how to pass arguments to the +lambda function via the function’s `payload` and examine the response. - -```r +``` r # example function that performs simple addition plus <- system.file("templates", "plus.js", package = "aws.lambda") @@ -79,46 +114,14 @@ if (!"plus" %in% funclist) { # invoke function invoke_function(func, payload = list(a = 2, b = 3)) -``` - -``` -## [1] 5 -``` - -```r invoke_function(func, payload = list(a = -5, b = 7)) ``` -``` -## [1] 2 -``` - - - - -## Installation - -[![CRAN](https://www.r-pkg.org/badges/version/aws.lambda)](https://cran.r-project.org/package=aws.lambda) -![Downloads](https://cranlogs.r-pkg.org/badges/aws.lambda) -[![Build Status](https://travis-ci.org/cloudyr/aws.lambda.png?branch=master)](https://travis-ci.org/cloudyr/aws.lambda) -[![codecov.io](https://codecov.io/github/cloudyr/aws.lambda/coverage.svg?branch=master)](https://codecov.io/github/cloudyr/aws.lambda?branch=master) - -This package is not yet on CRAN. To install the latest development version you can install from the cloudyr drat repository: - -```R -# latest stable version -install.packages("aws.s3", repos = c("cloudyr" = "http://cloudyr.github.io/drat")) -``` - -To install the latest development version from GitHub, run the following: - -```R -if (!require("ghit")){ - install.packages("ghit") -} -ghit::install_github("cloudyr/aws.lambda") +``` r +delete_function(func) ``` +----- ---- -[![cloudyr project logo](http://i.imgur.com/JHS98Y7.png)](https://github.com/cloudyr) +[![cloudyr project +logo](http://i.imgur.com/JHS98Y7.png)](https://github.com/cloudyr) From a55c651830133477107daa0ba9e6c648e08bf155 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Wed, 15 Apr 2020 09:55:14 -0500 Subject: [PATCH 14/14] Added cran comments. --- .Rbuildignore | 1 + cran-comments.md | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 cran-comments.md diff --git a/.Rbuildignore b/.Rbuildignore index c44c41b..51641fb 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -12,3 +12,4 @@ knitreadme.sh ^\.github.? ^LICENSE\.md$ ^README\.Rmd$ +^cran-comments\.md$ diff --git a/cran-comments.md b/cran-comments.md new file mode 100644 index 0000000..e5ca9ae --- /dev/null +++ b/cran-comments.md @@ -0,0 +1,11 @@ +## Test environments +* local R installation, R 3.6.3 +* ubuntu 16.04 (on travis-ci), R 3.6.3 +* win-builder (devel) + +## R CMD check results + +0 errors | 0 warnings | 1 note + +* This is a new release. +** This isn't really new, but I'm taking over an orphaned package.