Produces a docker container running R (>=4) that can be loaded to ECR and serve requests from lambda functions. Lambda functions are loaded into the functions.R file.
You should run the most recent version of Docker and have access to aws cli as well. You should also have a docker hub account that you can push images to. Run aws configure to set your region, secret keys and other details. Drop your R functions in the functions.R script.
- Build the docker container with
docker build -t <docker username>/rlambda .. - You can run locally as
docker run -p 9000:8080 <docker username>/rlambda. - Create the ecr repo
aws ecr create-repository --repository-name rlambda --image-scanning-configuration scanOnPush=true. - Tag the docker container with the resulting
repositoryUriwith the following command:docker tag <docker username>/rlambda:latest <repositoryUri>/rlambda:latest. - Push container to ECR:
aws ecr get-login-password | docker login --username AWS --password-stdin <repositoryUri>/rlambda && docker push <respositoryUri>/rlambda:latest. - Once the container is uploaded create a lambda function and choose container image as the source. Choose the container image URI of the docker container you just pushed.
- Create the function and then configure the timeout settings to 30 seconds or more and edit the image configuration for CMD to point to the function you want to call such as
functions.filterPosts. - Function
filterPostsshows how to incorporate library call for a function within the docker container.
Credit for this goes to mdneuzerling with his post here.