AWS Lambda
EFS
Mounting EFS
AWS Tutorial
Cloud Computing

How to mount EFS on a Lambda function?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

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

  1. Navigate to Amazon EFS in the AWS Management Console.
  2. 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:

  1. 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.

Course illustration
Course illustration

All Rights Reserved.