Code Monkey home page Code Monkey logo

aws-lambda-r-runtime's Introduction

aws-lambda-r-runtime

Build Status

This project makes it easy to run AWS Lambda Functions written in R.

Example

To run the example, we need to create a IAM role executing our lambda. This role should have the following properties:

  • Trusted entity – Lambda.
  • Permissions – AWSLambdaBasicExecutionRole.

Furthermore you need a current version of the AWS CLI.

Then create a lambda function which uses the R runtime layer:

cd example/
chmod 755 script.R
zip function.zip script.R
# current region
region=$(aws configure get region)
# latest runtime layer ARN for R 3.6.0 in most regions
# for an accurate list, please have a look at the deploy section of the travis ci build log
# https://travis-ci.com/bakdata/aws-lambda-r-runtime
runtime_layer=arn:aws:lambda:$region:131329294410:layer:r-runtime-3_6_0:13
aws lambda create-function --function-name r-example \
    --zip-file fileb://function.zip --handler script.handler \
    --runtime provided --timeout 60 \
    --layers ${runtime_layer} \
    --role <role-arn>

The function simply increments 'x' by 1. Invoke the function:

aws lambda invoke --function-name r-example \
    --payload '{"x":1}' response.txt
cat response.txt

The expected result should look similar to this:

2

Using packages

We also provide a layer which ships with some recommended R packages, such as Matrix. This example lambda shows how to use them:

cd example/
chmod 755 matrix.R
zip function.zip matrix.R
# current region
region=$(aws configure get region)
# latest runtime layer ARN for R 3.6.0 in most regions
# for an accurate list, please have a look at the deploy section of the travis ci build log
# https://travis-ci.com/bakdata/aws-lambda-r-runtime
runtime_layer=arn:aws:lambda:$region:131329294410:layer:r-runtime-3_6_0:13
# latest recommended layer ARN for R 3.6.0 in most regions
# for an accurate list, please have a look at the deploy section of the travis ci build log
# https://travis-ci.com/bakdata/aws-lambda-r-runtime
recommended_layer=arn:aws:lambda:$region:131329294410:layer:r-recommended-3_6_0:13
aws lambda create-function --function-name r-matrix-example \
    --zip-file fileb://function.zip --handler matrix.handler \
    --runtime provided --timeout 60 --memory-size 3008 \
    --layers ${runtime_layer} ${recommended_layer} \
    --role <role-arn>

The function returns the second column of some static matrix. Invoke the function:

aws lambda invoke --function-name r-matrix-example response.txt
cat response.txt

The expected result should look similar to this:

[4,5,6]

Provided layers

Layers are only accessible in the AWS region they were published. We provide the following layers:

r-runtime

R, httr, jsonlite, aws.s3, logging

Available AWS regions:

  • ap-northeast-1
  • ap-northeast-2
  • ap-south-1
  • ap-southeast-1
  • ap-southeast-2
  • ca-central-1
  • eu-central-1
  • eu-north-1
  • eu-west-1
  • eu-west-2
  • eu-west-3
  • sa-east-1
  • us-east-1
  • us-east-2
  • us-west-1
  • us-west-2

Available R versions:

  • 3_5_1
  • 3_5_3
  • 3_6_0

Latest ARN can be retrieved from the Travis CI build log. In general, it looks this:

arn:aws:lambda:$region:131329294410:layer:r-runtime-$r_version:$layer_version

Automated command for retrieving the ARN does not work currently:

aws lambda list-layer-versions --max-items 1 --no-paginate  \
    --layer-name arn:aws:lambda:${region}:131329294410:layer:r-runtime-${r_version} \
    --query 'LayerVersions[0].LayerVersionArn' --output text

r-recommended

The recommended packages that ship with R: boot, class, cluster, codetools, foreign, KernSmooth, lattice, MASS, Matrix, mgcv, nlme, nnet, rpart, spatial, survival

Available AWS regions:

  • ap-northeast-1
  • ap-northeast-2
  • ap-south-1
  • ap-southeast-1
  • ap-southeast-2
  • ca-central-1
  • eu-central-1
  • eu-north-1
  • eu-west-1
  • eu-west-2
  • eu-west-3
  • sa-east-1
  • us-east-1
  • us-east-2
  • us-west-1
  • us-west-2

Available R versions:

  • 3_5_1
  • 3_5_3
  • 3_6_0

Latest ARN can be retrieved from the Travis CI build log. In general, it looks this:

arn:aws:lambda:$region:131329294410:layer:r-recommended-$r_version:$layer_version

Automated command for retrieving the ARN does not work currently:

aws lambda list-layer-versions --max-items 1 --no-paginate  \
    --layer-name arn:aws:lambda:${region}:131329294410:layer:r-recommended-${r_version} \
    --query 'LayerVersions[0].LayerVersionArn' --output text

r-awspack

The aws.s3 package. It used to contain the awspack package but unfortunately this package has been retired. You can still find it in old versions of the layer that have been published before 2020.

Available AWS regions:

  • ap-northeast-1
  • ap-northeast-2
  • ap-south-1
  • ap-southeast-1
  • ap-southeast-2
  • ca-central-1
  • eu-central-1
  • eu-north-1
  • eu-west-1
  • eu-west-2
  • eu-west-3
  • sa-east-1
  • us-east-1
  • us-east-2
  • us-west-1
  • us-west-2

Available R versions:

  • 3_5_1
  • 3_5_3
  • 3_6_0

Latest ARN can be retrieved from the Travis CI build log. In general, it looks this:

arn:aws:lambda:$region:131329294410:layer:r-awspack-$r_version:$layer_version

Automated command for retrieving the ARN does not work currently:

aws lambda list-layer-versions --max-items 1 --no-paginate  \
    --layer-name arn:aws:lambda:${region}:131329294410:layer:r-awspack-${r_version} \
    --query 'LayerVersions[0].LayerVersionArn' --output text

Documentation

The lambda handler is used to determine both the file name of the R script and the function to call. The handler must be separated by ., e.g., script.handler.

The lambda payload is unwrapped as named arguments to the R function to call, e.g., {"x":1} is unwrapped to handler(x=1).

The lambda function returns whatever is returned by the R function as a JSON object.

Building custom layers

In order to install additional R packages, you can create a lambda layer containing the libraries, just as in the second example. You must use the the compiled package files. The easiest way is to install the package with install.packages() and copy the resulting folder in $R_LIBS. Using only the package sources does not suffice. The file structure must be R/library/<my-library>. If your package requires system libraries, place them in R/lib/.

You can use Docker for building your layer. You need to run ./docker_build.sh first. Then you can install your packages inside the container and copy the files to your machine. See awspack/ for an example. The build.sh script is used to run the docker container and copy sources to your machine. The entrypoint.sh script is used for installing packages inside the container.

Debugging

In order to make the runtime log debugging messages, you can set the environment variable LOGLEVEL to DEBUG.

Limitations

AWS Lambda is limited to running with 3GB RAM and must finish within 15 minutes. It is therefore not feasible to execute long running R scripts with this runtime. Furthermore, only the /tmp/ directory is writeable on AWS Lambda. This must be considered when writing to the local disk.

Building

To build the layer yourself, you need to first build R from source. We provide a Docker image which uses the great docker-lambda project. Just run ./build.sh <version> and everything should be build properly.

If you plan to publish the runtime, you need to have a recent version of aws cli (>=1.16). Now run the <layer>/deploy.sh script. This creates a lambda layer named r-<layer>-<version> in your AWS account. You can use it as shown in the example.

Compiling on EC2

In case the Docker image does not properly represent the lambda environment, we also provide a script which launches an EC2 instance, compiles R, and uploads the zipped distribution to S3. You need to specify the R version, e.g., 3.6.0, as well as the S3 bucket to upload the distribution to. Finally, you need to create an EC2 instance profile which is capable of uploading to the S3 bucket. See the AWS documentation for details. With everything prepared, you can run the script:

./remote_compile_and_deploy.sh <version> <bucket-name> <instance-profile>

The script will also take care of terminating the launched EC2 instance.

To manually build R from source, follow these steps:

Start an EC2 instance which uses the Lambda AMI:

aws ec2 run-instances --image-id ami-657bd20a --count 1 --instance-type t2.medium --key-name <my-key-pair>

Now run the compile.sh script in r/. You must pass the R version as a parameter to the script, e.g., 3.6.0. The script produces a zip containing a functional R installation in /opt/R/. The relevant files can be found in r/build/bin/. Use this R distribution for building the layers.

Testing

After building all layers, you can test it locally with SAM CLI and Docker. Install it via pipenv install --dev. Then run python3 -m unittest. This will spawn a local lambda server via Docker and invokes the lambdas defined in template.yaml.

aws-lambda-r-runtime's People

Contributors

aheise avatar philipp94831 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-lambda-r-runtime's Issues

Image does not exist

Thought I would try the remote compile option to see if i had more luck with that, but sadly that fails as the image does not seem to exist ....

An error occurred (InvalidAMIID.NotFound) when calling the RunInstances operation: The image id '[ami-657bd20a]' does not exist

there is no package called ‘Rcpp’

Built using the build.sh (with docker) on macOs

Deployed the layers via

runtime/deploy.sh
and
recommended/deploy.sh

When i create function that uses them and try to run it i get

there is no package called ‘Rcpp’

any thoughts gratefully received

Please provide pre-compiled layers

Sorry but I don't understand what to do here, I'm on windows and I don't understand how to run these .sh files.

I see that you provided arns for your layers but I also don't understand how to download someone else's layer by arn.

Could you just provide a pre-compiled zip for the R custom runtime?

I tried running using git but I got the following error :

The command '/bin/sh -c wget -q https://cran.r-project.org/src/base/R-3/R-${VERSION}.tar.gz && mkdir ${R_DIR} && tar -xf R-${VERSION}.tar.gz && mv R-${VERSION}/* ${R_DIR} && rm R-${VERSION}.tar.gz' returned a non-zero code: 8

Can the run time printing the event to console be controlled on the user side?

I believe (though I may be wrong) that

loginfo("Invoking function '%s' with parameters:\n%s", function_name, to_str(params))
is logging the entire event to cloudwatch.

I can see the value in doing this in many cases, but in the case where you may be passing a large data set in the body of the json, this makes the logs, and the in console test return, pretty impossible to use.

Is it possible to control this in your 'default' R runtime layers, without the user forking the project and rolling their own?

I've naively included logging::loglevel("WARN") at the start of script.R, though this doesn't seem to make an impact.

An ideal hypothetical for me would be to be able to specifically not log the body of json
An acceptable one would be to not capture logs from the runtime.R at all
Another acceptable one would be to control the log level of runtime.R, though this shouldn't impact the main script.R log level

I'm happy to do my best to look into this as well (I can see your project is picking up steam 🚂 !) but I might need a bit of guidance about where to start and how to implement.

Workspace cleared between invocations

Most AWS lambda runtimes keep global variables around between invocations. The R runtime seems to clear it with rm(list = ls()) and then source the code again after each invocation. This means we cannot cache data between calls and cannot keep database connections open. Is there any reason why the R runtime was implemented this way?

Invalid JSON

While exposing the lambda through API gateway in passthrough mode I found that the json payload was getting split on the commas thus failing in the conversion to a R object.

In order to have the complete json pass as a string I had to adjust the bootstrap file to put the $EVENT_DATA between double quotes.

/opt/R/bin/Rscript /opt/runtime.R “$EVENT_DATA” $REQUEST_ID.

Is it possible to access the aws lambda context from this R runtime layer?

I see that in the runtime you create the EVENT_DATA from event_response which is driven from the event_url:

EVENT_DATA <- rawToChar(event_response$content)
result <- invoke_lambda(EVENT_DATA, function_name)

Would this also expose the context of the invocation? Specifically the log_stream_name as outlined here in python? How would I access that? What would the variable be called?

https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html

I have a use case where I need to pass this log_stream_name over to the client system to log to help them with bug fixing. I'm looking for a variable that is a string set at a cold start similar to: 2019/12/10/[$LATEST]dc1cbcfbd4a24f0e9abcd3c8d44bc041

Any suggestions as to how I can access that from my lambda logic?

N.B I don't believe (maybe wrongly), that this is the "requestContext" of the body of the event. I've only seen that have info about the account id, and request id, but never (yet) the cloud watch log stream name mentioned in the docs above.

This may not be helpful, but I've found a rust custom runtime which seems to be an example of what I'm looking for, creating a string called log_stream_name:

https://github.com/awslabs/aws-lambda-rust-runtime/blob/master/lambda-runtime-core/src/context.rs

docker_build results in error

Hi,

I cloned the repository locally and ran docker_build.sh, but step 5 throws up this error:

The command '/bin/sh -c wget -q https://cran.r-project.org/src/base/R-3/R-${VERSION}.tar.gz && mkdir ${R_DIR} && tar -xf R-${VERSION}.tar.gz && mv R-${VERSION}/* ${R_DIR} && rm R-${VERSION}.tar.gz' returned a non-zero code: 8

More details:

Renatos-MacBook-Pro-2:aws-lambda-r-runtime renatopb$ ./docker_build.sh 3_6_0
Sending build context to Docker daemon  328.2kB
Step 1/9 : FROM lambci/lambda:build-provided
build-provided: Pulling from lambci/lambda
838b886eca89: Pull complete 
c57f92b37644: Pull complete 
c94065e4fef9: Pull complete 
Digest: sha256:4d400577d34d84a224264572e436151fbcdee45436f22ec1be26c7c7ec99811e
Status: Downloaded newer image for lambci/lambda:build-provided
 ---> 49b76ef13c9e
Step 2/9 : RUN yum install -q -y wget     readline-devel     xorg-x11-server-devel libX11-devel libXt-devel     curl-devel     gcc-c++ gcc-gfortran     zlib-devel bzip2 bzip2-libs     java-1.8.0-openjdk-devel
 ---> Running in 36cc3bb309ef
Package readline-devel-6.2-9.14.amzn1.x86_64 already installed and latest version
Package libX11-devel-1.6.0-2.2.12.amzn1.x86_64 already installed and latest version
Package libXt-devel-1.1.4-6.1.9.amzn1.x86_64 already installed and latest version
Package libcurl-devel-7.61.1-7.91.amzn1.x86_64 already installed and latest version
Package gcc-c++-4.8.5-1.22.amzn1.noarch already installed and latest version
Package gcc-gfortran-4.8.5-1.22.amzn1.noarch already installed and latest version
Package zlib-devel-1.2.8-7.18.amzn1.x86_64 already installed and latest version
Package bzip2-1.0.6-8.12.amzn1.x86_64 already installed and latest version
Package bzip2-libs-1.0.6-8.12.amzn1.x86_64 already installed and latest version
Removing intermediate container 36cc3bb309ef
 ---> 91d15e79072d
Step 3/9 : ARG VERSION=3.6.0
 ---> Running in cb6c95c5d2bd
Removing intermediate container cb6c95c5d2bd
 ---> d917d30523fe
Step 4/9 : ARG R_DIR=/opt/R/
 ---> Running in cc054eb53b4a
Removing intermediate container cc054eb53b4a
 ---> c2b9a80a08ce
Step 5/9 : RUN wget -q https://cran.r-project.org/src/base/R-3/R-${VERSION}.tar.gz &&     mkdir ${R_DIR} &&     tar -xf R-${VERSION}.tar.gz &&     mv R-${VERSION}/* ${R_DIR} &&     rm R-${VERSION}.tar.gz
 ---> Running in 1c7b50da850f
The command '/bin/sh -c wget -q https://cran.r-project.org/src/base/R-3/R-${VERSION}.tar.gz &&     mkdir ${R_DIR} &&     tar -xf R-${VERSION}.tar.gz &&     mv R-${VERSION}/* ${R_DIR} &&     rm R-${VERSION}.tar.gz' returned a non-zero code: 8
Renatos-MacBook-Pro-2:aws-lambda-r-runtime renatopb$

I'm running it on macOS Mojave 10.14.5 and docker 18.09.2.

Am I doing it wrong?

AMI in remote_compile_and_deploy.sh is not public

The command:

instance_id=$(aws ec2 run-instances --image-id ami-657bd20a --count 1 --instance-type t2.medium \ --instance-initiated-shutdown-behavior terminate --iam-instance-profile Name='"'${PROFILE}'"' \ --user-data '#!/bin/bash

calls an AMI that either doesn't exist or isn't publicly available. What AMI would you recommend we use instead?

aws.lambda integration?

I'm resurrecting the {aws.lambda} package, and, once it's alive, I plan to update it to make creation of R lambdas as easy as possible.

If it's ok with you, I'd like to integrate your provided layers directly into the package (well, their names), so that users can launch R lambdas without having to dig into things too far (I'm sorting out how easy I can make things for packages beyond what you've done, but I'd at least like to allow use of those packages).

Do you have any objections?

API gateway curl request example

I've deployed your example api on lambda, and opened api gateway. Test succeeded.
Can you give an example how can we make request with curl ?

what I tries so far

library(curl)
h <- new_handle()
handle_setform(h, payload = jsonlite::toJSON( data.frame(x = 1 ) ) )  
handle_setform(h, payload = jsonlite::toJSON(  list("x" = 1 ) ) )  # this also sisnt work
req <- curl_fetch_memory("https://myapigateway.execute-api.eu-central-1.amazonaws.com/default/r-example", handle = h)
jsonlite::prettify(rawToChar(req$content))
library(crul)
req <-  crul::HttpRequest$new(
  url = "https://myapigateway.execute-api.eu-central-1.amazonaws.com/default/r-example", 
  headers = list(`Content-Type` = "application/json")
)$post(payload = jsonlite::toJSON( list(x = 1 ) ) )

out <- AsyncVaried$new(req)
out$request()
out$parse() 

libR.so: cannot open shared object file: No such file or directory

Hi,
Im attempting to install and use the tibble package. I've successfully created a layer containing the binaries of the package and its deps, in aR/library/ directory. When I run the lambda which uses the package I'm receiving the following error:

Error: package or namespace load failed for ‘tibble’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/R/library/rlang/libs/rlang.so':
  libR.so: cannot open shared object file: No such file or directory

I've tried a few things but with no luck. It would appear the rlang package is looking for a libR.so file - which dosent exist. I see there is a libRblas.so file in /opt/R/lib but im not sure how that relates to the missing libR.so file.
From reading here it would suggest an additional arg must be set when building R from source.

Flag --enable-R-shlib causes the make process to build R as a dynamic (shared) library, typically called libR.so, and link the main R executable R.bin against that library

Before I attempt to try and build my own R from source I wanted to check with you, as you might have more information/context.
Thanks

Event source length limited by the way it is passed to the runtime

There seems to be some hard limit on the event source that this runtime will process.

I am providing a large event source, a json stucture with one field containing an array of 20,000 observations (each observation has 3 fields).

I am receiving the following runtime error

START RequestId: da723778-9f4e-4198-a889-567b0ca8d790 Version: $LATEST
/opt/bootstrap: line 13: /opt/R/bin/Rscript: Argument list too long
END RequestId: da723778-9f4e-4198-a889-567b0ca8d790
REPORT RequestId: da723778-9f4e-4198-a889-567b0ca8d790 Duration: 112.00 ms Billed Duration: 200 ms Memory Size: 1028 MB Max Memory Used: 285 MB
RequestId: da723778-9f4e-4198-a889-567b0ca8d790 Error: Runtime exited with error: exit status 1
Runtime.ExitError

Event source json data attached as txt (would not allow me to upload json file)

The R function is not particularly relevant as its not getting that far, but included below anyway. Its dependent on PlackettLuce package which i have loaded in a separate layer. But this should be reproducable with a very basic Lambda function as it appears that the error is an the runtime invocation before the handler is event called.

library(PlackettLuce)

handler <- function(cjs) {
    #NOW USE FUNCTIONS FROM THE PLACKETT-LUCE PACKAGE TO DO THE WORK
    cjranks=rankings(cjs,id=1,item=2,rank=3)#put into bespoke format for PlackettLuce package
    con=connectivity(cjranks)#check connectivity of design (note that any individual object winning/losing all comparisons may be deemd an issue when it isn't really)
    mod <- PlackettLuce(cjranks)#fit Plackett-Luce model

    #more detailed connectivity (how many other objects in each objects cluster)
    connect.oth=sapply(1:length(con$membership),function(i) con$csize[con$membership[i]]-1)

    #READ THE COEFFICIENTS AND STANDARD ERRORS
    estmeas=coef(mod,ref=NULL)
    estse=sqrt(diag(vcov(mod, ref=NULL)))
    measures.data.frame=data.frame(id=names(estmeas)
        ,measure=estmeas
        ,se=estse
        ,connectivity.no=con$no
        ,connect.oth=connect.oth)

    #VIEW THE OUTPUT
    measures.data.frame

}

testdata.txt

This looks releavant (https://stackoverflow.com/questions/24658534/usr-bin-rscript-argument-list-too-long)

Create layer for AWS libraries

I will suggest to add some more base packages for AWS service as R code can easily integrate those aws components:
library(aws.sqs)
library(aws.signature)
library(aws.s3) # already saw there, that's great
library(aws.sns)
library(utils)
library(tools)

Error running matrix.R

I followed the instructions in the README to run the matrix.R example. However, the lambda execution fails with the following error message:

[1] "Sourcing 'matrix.r'"
Error in file(filename, "r", encoding = encoding) : 
cannot open the connection
Calls: source -> file
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'matrix.r': No such file or directory
Execution halted

script.r and script.R appear to be case sensitive and differ by region

Thanks for the ground work. This is really exciting.

In working through the examples I believe I've found an 'undocumented inconsitency':

I can run the listed examples perfectly.

I then attempted to 'translate' your shell scripts to support region eu-west-2

  1. I use your template to check for the most recent publishing of R v3.6.0
aws lambda list-layer-versions --max-items 1 --no-paginate  \
    --layer-name arn:aws:lambda:eu-west-2:131329294410:layer:r-runtime-3_6_0 \
    --query 'LayerVersions[0].LayerVersionArn' --output text

Which returns arn:aws:lambda:eu-west-2:131329294410:layer:r-runtime-3_6_0:4

  1. I create a new function where I supply the above, modifying the :
chmod 755 script.r

zip function.zip script.r

aws lambda create-function --function-name r-example \
--zip-file fileb://function.zip --handler script.increment \
--runtime provided --timeout 60 \
--layers arn:aws:lambda:eu-west-2:131329294410:layer:r-runtime-3_6_0:4 \
--role <my-role-arn> --region eu-west-2

This returned 200, and function is created in eu-west-2, crucially I have used the identical script.r (lower case)

  1. Attempting to invoke the new version
aws lambda invoke --function-name r-example \
    --payload '{"x":1}' --region eu-west-2 response.txt      
cat response.txt

return:

{
    "StatusCode": 200,
    "FunctionError": "Unhandled",
    "ExecutedVersion": "$LATEST"
}

Checking in the web console I see this in cloud watch:

2019-05-31 14:55:25 INFO::Sourcing 'script.R'
Error in file(filename, "r", encoding = encoding) : 
cannot open the connection
Calls: source -> file
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'script.R': No such file or directory
Execution halted
  1. I open the lambda in console, and manually rename the script.r (lower) to script.R (upper)

  2. I reinvoke as step 2 with success

{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}
cat response.txt
{"result":2}

Is this an accidental side effect from the differing r-runtime layers? How can I workout which needs what? should there be a uniform treatment?

Thanks again for the work 😄

AccessDeniedException when calling the ListLayerVersions operation

When trying to run:

aws lambda list-layer-versions --max-items 1 --no-paginate --layer-name arn:aws:lambda:us-east-1:131329294410:layer:r-runtime-3_6_0  --query 'LayerVersions[0].LayerVersionArn' --output text

I get this error

An error occurred (AccessDeniedException) when calling the ListLayerVersions operation: 
User: arn:aws:iam::273907563187:user/tyler is not authorized to perform: 
lambda:ListLayerVersions on resource: arn:aws:lambda:us-east-1:131329294410:layer:r-runtime-3_6_0

Did something change recently? I have been able to run this before without any issue.

How should complex json calls (i.e. from apigateway) be handled?

In practice the call to the service is more complex than {'x':1}.

For instance sam has an example as follows:

Davids-MBP:~ davidparr$ sam local generate-event apigateway aws-proxy
{
  "body": "eyJ0ZXN0IjoiYm9keSJ9",
  "resource": "/{proxy+}",
  "path": "/path/to/resource",
  "httpMethod": "POST",
  "isBase64Encoded": true,
  "queryStringParameters": {
    "foo": "bar"
  },
  "pathParameters": {
    "proxy": "/path/to/resource"
  },
  "stageVariables": {
    "baz": "qux"
  },
  "headers": {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
    "Accept-Encoding": "gzip, deflate, sdch",
    "Accept-Language": "en-US,en;q=0.8",
    "Cache-Control": "max-age=0",
    "CloudFront-Forwarded-Proto": "https",
    "CloudFront-Is-Desktop-Viewer": "true",
    "CloudFront-Is-Mobile-Viewer": "false",
    "CloudFront-Is-SmartTV-Viewer": "false",
    "CloudFront-Is-Tablet-Viewer": "false",
    "CloudFront-Viewer-Country": "US",
    "Host": "1234567890.execute-api.us-east-1.amazonaws.com",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Custom User Agent String",
    "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
    "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
    "X-Forwarded-For": "127.0.0.1, 127.0.0.2",
    "X-Forwarded-Port": "443",
    "X-Forwarded-Proto": "https"
  },
  "requestContext": {
    "accountId": "123456789012",
    "resourceId": "123456",
    "stage": "prod",
    "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
    "requestTime": "09/Apr/2015:12:34:56 +0000",
    "requestTimeEpoch": 1428582896000,
    "identity": {
      "cognitoIdentityPoolId": null,
      "accountId": null,
      "cognitoIdentityId": null,
      "caller": null,
      "accessKey": null,
      "sourceIp": "127.0.0.1",
      "cognitoAuthenticationType": null,
      "cognitoAuthenticationProvider": null,
      "userArn": null,
      "userAgent": "Custom User Agent String",
      "user": null
    },
    "path": "/prod/path/to/resource",
    "resourcePath": "/{proxy+}",
    "httpMethod": "POST",
    "apiId": "1234567890",
    "protocol": "HTTP/1.1"
  }
}

When this is held as a 'test' even in the console (and potentially therefore also when used in practice?) the script.R fails with:

Error in increment(body = myData  : 
  unused arguments (resource = "/{proxy+}", path = "/path/to/resource", httpMethod = "POST", isBase64Encoded = TRUE, queryStringParameters = list("bar"), pathParameters = list("/path/to/resource"), stageVariables = list("qux"), headers = list("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "gzip, deflate, sdch", "en-US,en;q=0.8", "max-age=0", "https", "true", "false", "false", "false", "US", "1234567890.execute-api.eu-west-2.amazonaws.com", "1", "Custom User Agent String", "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", 
    "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==", "127.0.0.1, 127.0.0.2", "443", "https"), requestContext = list("123456789012", "123456", "prod", "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "09/Apr/2015:12:34:56 +0000", 1428582896000, list(NULL, NULL, NULL, NULL, NULL, "127.0.0.1", NULL, NULL, NULL, "Custom User Agent String", NULL), "/prod/path/to/resource", "/{proxy+}", "POST", "1234567890", "HTTP/1
Calls: do.call
Execution halted

In some cases the structure can be predetermined, so in a toy case the increment function from the example becomes:

increment <- function(body, resource, path, httpMethod, isBase64Encoded, queryStringParameters, pathParameters, stageVariables, headers, requestContext) {
  ...
}

However there is no guarantee in lambda of the source of the json, or really it's wider structure. It could need to accept multiple trigger patterns. Is it correct to fail if the json isn't exactly what is expected, even if all the cruft (resource, path, httpMethod, isBase64Encoded, queryStringParameters, pathParameters, stageVariables, headers, requestContext) has no bearing on the calculation? Is it possible to absorb these unimportant arguments in the event currently?

unable to deploy custom runtime

Hi I have followed the steps

i am able to run ./docker_build.sh 3.6.0
followed by ./build.sh 3.6.0

however I am not able to find /deploy.sh file and if I use the deploy.sh available at the root it fails with the following error
aws: error: the following arguments are required: --template-file

here are my details

aws-cli/1.16.55 Python/3.7.1 Darwin/18.7.0 botocore/1.13.32

build.sh chown:illegal group name

Hi,

I am trying to run the build.sh script, it seems to get right to the end ...

Successfully tagged lambda-r:build-3.6.0

but then errors with

chown: myusername: illegal group name

any thoughts

Running on mac

Thanks, Ed

Couldn't find valid bootstrap

Hi there,

When I try to invoke the sample function script.R in this guide using arn:aws:lambda:ap-southeast-2:131329294410:layer:r-recommended-3_6_0:13, I get:

{
    "StatusCode": 200,
    "FunctionError": "Unhandled",
    "ExecutedVersion": "$LATEST"
}

And in the response:

{"errorMessage":"RequestId: 5e1a1559-17e8-4233-b866-f14335722a3e Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]","errorType":"Runtime.InvalidEntrypoint"}

I'm still new to Lambda, so I might just be doing this wrong! I got the layer ARN from Travis CI, and it seemed to indicate that it'd built successfully.

Remove unecessary files/folders from libraries

I'm not an expert in R, but this repository was very useful for building a R lambda for a client, problem is, its really easy to reach lambda's limitation, some R libraries are huge in size.

But I noticed you can shave several megabytes off by removing some folders like docs, help, html, examples, tests, translations.

Would be cool to add this removal logic to the bash files, both for creating layers with libraries and for the bootstrap layer

problems running / building my own runtime layers

Hi, I'd like to use your layers but in the us-west-2 region where all of my other cloud infrastructure is located. It appears that the layer r-runtime at least is not available in that region.

Do you know of a way to copy a layer to another region? Seems like aws lambda get-layer-version ought to work but for me that just prints out the version of the aws CLI.

Failing that, I can try and build/publish it myself, but I notice that your scripts grab the R source from an S3 bucket (aws-lambda-r-runtime) that I do not have access to.

I can change this to another bucket, but I was wondering how the R source zip file was created. Typically the R source is distributed as a .tar.gz file; did you modify this source tarball in any way, and if so is that documented somewhere?

Creating layer

Hi Philip,

Do I have to run the build_recommended to get the layer? Or an I just zip R/library/ and load it manually through AWS lambda layers? I tried running build_recommended and it's creating R/library but the folder is empty and it's not creating a zip.

How to create a layer with additional packages

hi,
everything works great for me on lambda
I am trying to follow your guidelines and add four new libraries to my lambda:
biostrings, httr, stringr and deployr

i am creating a new layer with this script ... (i run it after build_recommend...)

#!/bin/bash

set -euo pipefail
rm -rf R/
mkdir -p R/library
cd R/library
wget https://cran.r-project.org/src/contrib/httr_1.4.0.tar.gz
wget https://bioconductor.org/packages/release/bioc/src/contrib/Biostrings_2.50.2.tar.gz
wget https://cran.r-project.org/src/contrib/stringr_1.4.0.tar.gz
wget https://cran.r-project.org/src/contrib/dplyr_0.8.0.1.tar.gz
ls *.tar.gz | xargs -i tar -xvzf {}
rm *.tar.gz
cd ..
cd ..

chmod -R 755 R/
rm -f dorke.zip
zip -r -q dorke.zip R/

later i tell lambda to use the main layer (runtime) and this new layer
it's not working

would appreciate assistance

Update aws.s3 (check_region is now FALSE)

The package now has check_region = FALSE by default.

With check_region = TRUE there is an extra request for bucketLocation. Also one would need an explicit s3:bucketLocation permission on their buckets. If you don't know this, you just pull hair :/

Question about the two instances of install.packages

Which does what exactly? It's hard to follow what the difference is between this:
https://github.com/bakdata/aws-lambda-r-runtime/blob/master/Dockerfile#L28
and this
https://github.com/bakdata/aws-lambda-r-runtime/blob/master/r/compile.sh#L42

What is the functional difference between the two? Do they need to be in sync? Is one a base and the second meant to be r layer derivative specific?

Love this repo so far - will be fun to chain sfn with this :D :D

Layer version in README out of date

The layer version specified in the README (for both the runtime and recommended layer) is v1, which is outdated and still has issues. This should be updated to at least the latest published version (13) to ensure people are pulling the latest layer code

package or namespace load failed for ‘aws.s3’

When using only one r-runtime layer aws.s3 package works, but using own custom layer as well, gives

Error: package or namespace load failed for ‘aws.s3’ in dyn.load(file, DLLpath = DLLpath, ...):

aws.s3 seems to have been removed from CRAN too

Build fails as aws.s3 no longer on CRAN

get error saying not supported for 3.6.0

looking at the github repo seems you would need to update to use their drat repo

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"))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.