Amazon EFS Integration with Lambda and ECS - Shared File Systems in Serverless Architectures

Mount EFS on Lambda functions and ECS tasks to leverage shared file systems. Learn access point design and performance optimization techniques.

Integrating Lambda with EFS

When you mount EFS on a Lambda function, the file system becomes accessible under the /mnt path. While Lambda's /tmp directory is limited to 10 GB, EFS provides virtually unlimited storage. This is useful for processing large ML models, datasets, and temporary files. Configuration simply requires specifying the Lambda function's VPC settings (subnets, security groups) along with the EFS file system ID and access point ID. Since the Lambda function runs within a VPC, it must be placed in the same subnet as the EFS mount target or in a routable subnet.

Designing Access Points

EFS access points isolate file system access on a per-application basis. You configure a root directory (e.g., /app1, /app2) and POSIX user (UID/GID) for each access point, then assign different access points to different Lambda functions. Function A accesses only the /app1 directory via /mnt/efs, while Function B accesses only /app2, achieving clean separation. Enabling IAM authentication allows you to control access based on IAM roles through EFS file system policies, restricting specific Lambda functions to specific access points.

ECS Task Integration and Performance

Define an EFS volume in the ECS task definition and specify the mount path in the container definition's mountPoints. Multiple containers within the same task can share the same EFS volume, enabling sidecar patterns where a log collection container reads log files from the application container. From a performance perspective, mounting EFS adds several hundred milliseconds of latency during Lambda cold starts. You can minimize this impact by using Provisioned Concurrency to eliminate Lambda cold starts or by using Elastic throughput mode to ensure adequate EFS throughput. To learn about shared storage systematically, related books (Amazon) are a useful reference.

Pricing Considerations for EFS Integration

EFS pricing depends on the storage class and throughput mode. Standard storage costs approximately $0.30 per GB per month, while IA (Infrequent Access) costs approximately $0.016. When accessing EFS from Lambda, a VPC connection is required, which adds several seconds to cold start time. Elastic throughput mode is recommended for EFS, as it automatically scales based on access patterns. When Lambda's /tmp (up to 10 GB, free) is sufficient, avoiding EFS keeps things simpler and more cost-effective.

Summary

Integrating EFS with Lambda and ECS enables shared file systems even in serverless architectures. Access points isolate root directories and POSIX permissions per application, enabling data sharing between Lambda functions and processing of large files. Intelligent-Tiering also provides automatic storage cost optimization based on access frequency.