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}}