Download repo from Appsilon
git clone https://github.com/Appsilon/r-lambda-workflow
cd r-lambda-workflow
Setup a python virtual env (may not be necessary)
python3 -m venv r-lambda-env
source r-lambda-env/bin/activate
Install paramiko library
pip install paramiko
Validate you are signed into AWS on CLI and set your region
aws configure set default.region ca-central-1
Create an EC2 key pair and protect it
aws ec2 create-key-pair --key-name r-lambda --query 'KeyMaterial' --output text >> r-lambda.pem
chmod 600 r-lambda.pem
Validate SSH access from your IP in default security group
aws ec2 authorize-security-group-ingress \
--group-name default \
--protocol tcp \
--port 22 \
--cidr $(curl -s http://checkip.amazonaws.com/)/32
Replace the build_r.sh script with the one in this Gist
Create an R runtime base layer (this will take ~5 mins)
./setup_r_instance.py -k r-lambda.pem -i t2.large
./build_runtime.sh
Publish the base layer to your AWS account
aws lambda publish-layer-version --layer-name r-lambda-base-layer --zip-file fileb://runtime.zip
Create an AMI for use with package layer creation
./setup_r_instance.py -k r-lambda.pem -i t2.large -a create_ami -n r-lambda-ami
Create layer for R packages
./r_package_layer.py -k r-lambda.pem -i t2.large -m <ami-...> -p "lubridate, RODBC, plyr, jsonlite"
Publish the base layer to your AWS account
aws lambda publish-layer-version --layer-name r-lambda-packages-layer --zip-file fileb://packages.zip