I have a docker container, that installs python, R and rpy2. I then use python with the rpy2.robjects package to load the library lubridate (minimal reproducible example). On localhost, inside the docker container the following python script would work:
from rpy2.robjects import r, globalenv
def handler:
r('''library(lubridate)''')
And to give a minimal reproducible docker file:
Define function directory
ARG FUNCTION_DIR="/function"
Using python buster as base image.
FROM python:buster as build-image
RUN apt-get update -y
RUN apt-get install -y python3 r-base r-base-dev python3-pip python3-venv curl
RUN apt-get install -y libcairo-dev libedit-dev libnlopt-dev libxml2-dev libcurl4-openssl-dev
RUN apt-get install -y libgsl23 libgsl-dev libnlopt-dev libxml2-dev lsb-release
RUN pip3 install rpy2
COPY packages.R {FUNCTION_DIR}/package.R
RUN Rscript {FUNCTION_DIR}/packages.R
COPY app.py ${FUNCTION_DIR}/app.py
Install the runtime interface client REQUIRED FOR LAMBDA
RUN pip install --target ${FUNCTION_DIR} awslambdaric
WORKDIR ${FUNCTION_DIR}
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
CMD [ "app.handler" ]
You can assume that the packages.R file is minimal for lubridate to be loaded.
However when I try to run this code with AWS lambda (which supports container deployments), I get the following error(s):
.onLoad failed in loadNamespace() for 'lubridate', details:
call: system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE)
error: cannot popen '/usr/bin/which 'timedatectl' 2>/dev/null', probable reason 'Cannot allocate memory'
Error: package or namespace load failed for ‘tidyverse’:
.onLoad failed in loadNamespace() for 'lubridate', details:
call: system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE)
error: cannot popen '/usr/bin/which 'timedatectl' 2>/dev/null', probable reason 'Cannot allocate memory'
As you can see this is quite frustrating (after all aren't docker containers supposed to make localhost work the "exact" same as when deployed on a server!!!). Any help as to why this might be caused would be greatly appreciated. Thanks