Nick's Blog

Serverless deploy lambda – EACCES: permission denied, open ‘/home/ec2-user/jenkins/workspace/..’

I was working for a client on a serverless solution. The goal is to use serverless to deploy a nodejs application that monitoring S3 bucket and do certain task when there is a bucket event.

The project does not have container in place. so Jenkins slave is actually a centos ec2 instance. Because of the tied environment I’m working with. So I had a few file permission issue.

The way I use to resolve this issues is to give all file under node_module 644 and all directories 755.

sudo find /workspace/node_modules -type d -exec chmod 755 {} +
sudo find /workspace/node_modules -type f -exec chmod 644 {} +

This will help the jenkins pipeline to build.

In my case, the build went success, I have the lambda, s3 event, and logs are all in place. So I did a test on the trigger. it did hooked up the lambda function. But I was again got a permission issue when the lambda executes.

EACCES: permission denied, open '/var/task/node_modules/handler.js'
EACCES: permission denied, open '/var/task/node_modules/aws-sdk/..'

So it ends up having issue to execute the code from lambda. I added the following code in my pipeline and it fixes the problem.

sh "chmod 755 ${WORKSPACE}/handler.js"
sh "chmod 755 -R ${WORKSPACE}/node_modules/aws-sdk"