Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get write access to EFS from Lambda?

I've created a lambda function. I created a Elastic File System (EFS) and access points using all the default settings. I attached the EFS to the lambda function, again just using the defaults.

But! There is no write access to EFS.

What did I miss?

Hope some kind person knows :)

Notes....

The current answer doesn't seem to work. I've also been onto AWS support for over a week. They seem to think the EFS is not mounting.

EFS is mounted to lambda at = /mnt/fs

EFS Access point - Root Directory Path = / (A suggestion of changing this to /fs causes an internal server error, AWS support suggested /mnt/fs which also causes an internal service error).

AmazonElasticFileSystemClientFullAccess and AWSLambdaVPCAccessExecutionRole added to execution role.

Test Node js example:

exports.handler = function(event, ctx, callback) {
    const fs = require("fs");
    fs.mkdir('/mnt/fs/newfolder', { recursive: true }, (err) => {
        callback(null, {
            statusCode: 200,
            "content-type": "text/html",
            body: (err || "ok").toString()
        })
    });
};
like image 892
Gordon Truslove Avatar asked Dec 03 '20 21:12

Gordon Truslove


1 Answers

The aws documentation misses the part about posix user settings, but a blog post explains it.

To add EFS to lambda.

AmazonElasticFileSystemClientFullAccess and AWSLambdaVPCAccessExecutionRole permissions need to be added to the execution role.

EFS is mounted to lambda at = /mnt/fs EFS Access point path = /mnt/fs

Add a posix user to the acccess point. User 1000, group 1000 & permissions 0777.

As explained in this blog post:

https://aws.amazon.com/blogs/compute/using-amazon-efs-for-aws-lambda-in-your-serverless-applications/

like image 76
Gordon Truslove Avatar answered Oct 10 '22 01:10

Gordon Truslove