Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda EFS | EACCES: permission denied

So, I am trying to integrate my lambda function with EFS. I am able to access the root directory (as read-only from lambda) as I can see xyz directory available in my root dir. /mnt/ -> xyz

When I try to access /mnt/xyz or /mnt/xyz/ then I get this error:

{
  "errorType": "Error",
  "errorMessage": "EACCES: permission denied, scandir '/mnt/xyz/'",
  "trace": [
    "Error: EACCES: permission denied, scandir '/mnt/xyz/'",
    "    at Object.readdirSync (fs.js:948:3)",
    "    at Runtime.exports.handler (/var/task/index.js:19:24)",
    "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
  ]
}

Permission given to the access point: 777

like image 717
Nishant Thapliyal Avatar asked Aug 18 '20 06:08

Nishant Thapliyal


People also ask

Can you use EFS with Lambda?

Lambda integrates with Amazon Elastic File System (Amazon EFS) to support secure, shared file system access for Lambda applications. You can configure functions to mount a file system during initialization with the NFS protocol over the local network within a VPC.

How do you add permission to lambda function?

You can also use resource-based policies to grant invoke permission to an AWS service that invokes a function in response to activity in your account. Open the Functions page of the Lambda console. Choose a function. Choose Configuration and then choose Permissions.

What permissions would be required for the package to function correctly in an AWS Lambda environment?

The correct permissions for all executable files within a Lambda deployment package is 644 in Unix permissions numeric notation. For folders within a deployment package, the correct permissions setting is 755.


2 Answers

The issue that I was facing was related to the user/group id (ownership). The file was produced by an application running on AWS EC2 instance and consumed by AWS Lambda function.

To find the owner/group of files use cmd ls -al

enter image description here

To find the owner/group IDs use cmd ls -n

enter image description here

As the file produced by the root (UID: 0) I need to set the owner id and group id as 0 at EFS access point

enter image description here

This configuration resolved my issue.

like image 89
Nishant Thapliyal Avatar answered Oct 12 '22 20:10

Nishant Thapliyal


I tried to replicate the issue, and can verify that I had the same problem. The help came from the following GitHub issue: EFS permission denied.

The permission denied was caused by incorrectly set root and local mount point in the access point and lambda respectively. The correct setting that worked were:

Access point (note /lambda)

enter image description here

Lambda (note /mnt/lambda)

enter image description here

These settings enable successful access to the EFS.

like image 32
Marcin Avatar answered Oct 12 '22 20:10

Marcin