How to mount EFS on a Lambda function?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Amazon Elastic File System (EFS) provides scalable file storage for use with Amazon EC2, enabling rapid scaling of storage capacity and compatibility with NFS v4.1 or v4.0. Lambda functions, known for executing code without provisioning or managing servers, can now utilize EFS to manage file storage demands seamlessly. This article explains how to mount EFS on an AWS Lambda function, detailing the configuration, permissions, and potential use cases.
Prerequisites
Before proceeding, ensure you have the following:
- AWS Management Console Access: An active AWS account with necessary permissions.
- Amazon EFS and Lambda: Understanding of these services is necessary.
- AWS CLI: Optional, for alternative infrastructure management.
Setting Up EFS
1. Create an EFS File System
- Navigate to Amazon EFS in the AWS Management Console.
- Create File System:
- Specify the VPC within which the Lambda operates.
- Opt for the necessary Performance Mode (General Purpose is suitable for Lambda).
- Enable Burst Throughput if needed.
2. Configure EFS Access Points
An access point simplifies permissions:
- Create Access Point:
- Specify the root directory and permissions.
- Define the POSIX user and group settings to control access.
3. Mount Target
- Create Mount Targets in subnets within your VPC. Ensure each target is in an appropriate availability zone where your Lambda function operates.
Setting Up Lambda
1. Create or Modify a Lambda Function
- Navigate to AWS Lambda and create or select your function.
2. Configure VPC
- Ensure the Lambda function is associated with the same VPC as your EFS using the `VPC Configurations` in the Lambda configuration settings.
3. Permissions and IAM Roles
Create or modify the IAM role:
- Attach AWSLambdaENIManagementAccess policy for VPC access.
- Ensure the role permits access to EFS using a policy like:
- Navigate to the Lambda's File System configurations.
- Add File System:
- Select the EFS File System.
- Choose the created access point.
- Specify a local mount path, such as `/mnt/efs`.
- Security: Use VPC security groups to restrict EFS access.
- Performance: Pick performance modes based on workload demands.
- Data Persistence: EFS ensures persistence beyond Lambda execution limits.
- Cost Management: Be aware of costs associated with EFS storage and Lambda execution.
Related reading
- How to move a domain from Godaddy to AWS Route 53
- How to move all files and folder from one folder to another of S3 bucket in php with some short way?
- How to move files from amazon ec2 to s3 bucket using command line
- How to normalize a private key stored on AWS secrets manager
- How to pass a params from POST to AWS Lambda from Amazon API Gateway
- How to pass a querystring or route parameter to AWS Lambda from Amazon API Gateway
- How to pass an empty string as value of a field in dynamodb?
- how to pass an object to amazon SNS

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.