Lesson 2 of 2 Amazon EBS and EFS

Sharing File Storage Across Instances, Containers and Functions with EFS

This lesson explains how Amazon EFS provides a managed, elastic NFS file system that many EC2 instances, containers and Lambda functions can mount at the same time, across Availability Zones.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how an EFS file system is reached through mount targets in each Availability Zone.
  • Choose throughput modes and storage classes for a workload's performance and cost requirements.
  • Describe how access points and security controls separate applications that share a file system.
  • Explain when a Lambda function benefits from mounting EFS instead of using /tmp.

How EFS works

Amazon EFS is a Regional file system that many clients can mount at the same time. The following list describes how it works.

  • A file system is Regional and has a mount target in each Availability Zone, an elastic network interface with an IP address in a subnet.
  • Clients mount it over NFSv4.1; the mount targets' security group must allow inbound NFS (TCP 2049) from the clients.
  • Storage grows and shrinks automatically, and you pay for the data stored.
  • Many clients can read and write the same files at once, with standard Linux file semantics.

Performance and storage classes

Amazon EFS has three groups of settings, which control throughput, storage cost and resilience.

The throughput mode decides how much data clients can read and write per second. Elastic throughput scales up and down automatically with demand and is charged for the data transferred; it is the recommended mode for unpredictable or spiky workloads. Provisioned throughput sets a fixed level regardless of the amount stored, for workloads with steady, high demand. Bursting throughput grows with the amount of data stored and uses credits for short bursts, so a small file system can run out of credits and slow down.

The storage classes reduce cost for files that are rarely read. Standard holds active files, while Infrequent Access and Archive cost less to store but charge for access. Lifecycle management moves files that have not been accessed for a set period into the cheaper classes, and can move them back when they are read again. A Regional file system stores data across several Availability Zones, whereas a One Zone file system stores it in one zone for a lower price. The following table summarises the settings.

SettingOptions
Throughput modeElastic (scales automatically; recommended), Provisioned, or Bursting
Storage classesStandard, Infrequent Access and Archive, with lifecycle management moving files between them
AvailabilityRegional (across AZs) or One Zone for lower cost

Access points and security

EFS provides access points and several security controls. The following list describes them.

  • Access points give each application its own root directory and enforce a POSIX user and group ID, so applications sharing a file system cannot see each other's files.
  • IAM policies can require that clients use a specific access point and TLS.
  • Encryption at rest uses KMS, and the mount helper enables TLS in transit.

EFS with Lambda

A Lambda function attached to the same VPC can mount EFS through an access point, which suits large or shared files such as machine learning models, beyond the 10 GB maximum of /tmp.

ModelFunction:
  Type: AWS::Serverless::Function
  Properties:
    VpcConfig:
      SubnetIds: [!Ref PrivateSubnetA, !Ref PrivateSubnetB]
      SecurityGroupIds: [!Ref FunctionSecurityGroup]
    FileSystemConfigs:
      - Arn: !GetAtt ModelsAccessPoint.Arn
        LocalMountPath: /mnt/models        # must start with /mnt/
Troubleshooting scenario

Share files with EFS

Exam skills 1.2.1 · 1.3.2 · 4.1.1

Fix the problems a team meets when sharing an EFS file system, one at a time.

Log in to try this activity Interactive activities are free with an account.
Worked example

Storage for a scaled-out application

An application that stores uploaded files on its EC2 instance's EBS volume is moved behind a load balancer with four instances. Users now see files "disappear" depending on which instance serves them.

OptionFit
EBS volume per instanceEach instance sees only its own files: the cause of the problem
EBS Multi-AttachLimited to io1/io2 in one AZ and needs a cluster-aware file system: not suitable
Amazon EFS mounted on all instancesOne shared file system across AZs: fixes the problem
Amazon S3 with the SDKAlso fixes it, and suits files served to browsers; requires code changes

The team mounts EFS for a quick fix and plans to move to S3 later. EBS remains the right choice for each instance's operating system and for databases that need low-latency block storage.

Check yourself

How can a Lambda function use an EFS file system?

Show answer

The function must be connected to the VPC that contains the file system's mount targets, and it mounts the file system through an EFS access point under /mnt.

Exam Tips

Remember for the exam

  • A shared file system for many instances or Lambda functions points to EFS.
  • To give each application its own directory and POSIX identity on EFS, use EFS access points.
  • Lambda can mount EFS only when the function is attached to the VPC.
  • EFS mount targets need a security group that allows NFS on port 2049 from the clients.