skip to Main Content

I have deployed a docker container to AWS lambda and when I triggered function it gives me error but when I test it locally its working fine. it looks some permission issue related to some dirs but couldn’t understand how to fix that

Babel could not write cache to file: /var/task/node_modules/.cache/@babel/register/.babel.7.17.7.development.json 
due to a permission issue. Cache is disabled.
Error: EROFS: read-only file system, open '/var/task/reporting/a.pdf.html'
at Object.openSync (node:fs:585:3)
at Object.writeFileSync (node:fs:2155:35)
at _callee$ (/var/task/reporting/generate.js:220:8)
at tryCatch (/var/task/node_modules/regenerator-runtime/runtime.js:63:40)
at Generator.invoke [as _invoke] (/var/task/node_modules/regenerator-runtime/runtime.js:294:22)
at Generator.next (/var/task/node_modules/regenerator-runtime/runtime.js:119:21)
at asyncGeneratorStep (/var/task/reporting/generate.js:33:103)
at _next (/var/task/reporting/generate.js:35:194)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
errno: -30,
syscall: 'open',
code: 'EROFS',
path: '/var/task/reporting/a.pdf.html'
}

my Dockerfile:

FROM public.ecr.aws/lambda/python:3.8


COPY . . 


RUN yum update -y
#RUN yum -y groupinstall 'Development Tools'

# for developement only
RUN yum install vim-enhanced -y  

RUN yum install -y http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

RUN yum install -y npm

RUN yum  -y install nodejs
RUN npm install  --production
RUN yum -y install libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb libgbm-dev

RUN yum install -y chromium

RUN npm install chrome-aws-lambda --save-prod
RUN npm install puppeteer-core --save-prod

RUN pip install -r requirements.txt

CMD ["app.lambda_handler"]  

2

Answers


  1. The relevant error is this:

    Error: EROFS: read-only file system, open '/var/task/reporting/a.pdf.html'
    

    AWS Lambda does not allow you to write to that directory. You only have 512MB of writeable storage at /tmp.

    You did not provide code for your Python Lambda, but I would think that you are storing your file in that code in reporting/a.pdf.html. Since the Lambdas task root is /var/task you are actually writing it to /var/task/reporting/a.pdf.html.

    It should work when you change your code to store your files in /tmp/reporting/a.pdf.html.

    Login or Signup to reply.
  2. I think you should try uploading your file to an S3 bucket instead of generating it in /tmp. Like @Jens correctly pointed out in his answer that "AWS Lambda does not allow you to write to that directory."

    Please post your entire code so that we can have a look and help you better.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search