Overview
This guide provides a comprehensive overview of Amazon Elastic File System (EFS), a scalable and fully managed file storage service for use with Amazon EC2 instances. You will learn about the core concepts of EFS and how to create and manage EFS file systems using Terraform. EFS is ideal for a wide range of workloads, including web serving and content management, application development and testing, and media and entertainment workflows.
Prerequisites
Section titled “Prerequisites”Before you begin, you will need:
- An active University of Oregon AWS account.
- Terraform installed on your local machine.
- The AWS CLI installed and configured with your UO account credentials.
- An existing VPC and at least one subnet. You can follow our VPC guide to create one.
Core Concepts
Section titled “Core Concepts”Amazon EFS provides a simple, serverless, set-and-forget elastic file system. It is built to scale on demand to petabytes without disrupting applications, growing and shrinking automatically as you add and remove files, so you don’t need to manage capacity.
File System
Section titled “File System”The fundamental resource in EFS is the file system. Each file system has a unique ID and can be mounted by multiple EC2 instances simultaneously. Data is stored redundantly across multiple Availability Zones (AZs) for high availability and durability.
Mount Targets
Section titled “Mount Targets”To access your EFS file system from a VPC, you create one or more mount targets in the VPC. A mount target provides an IP address for an EFS file system, which you can use in a mount command. You should create a mount target in each AZ where you have EC2 instances that need to access the file system.
Access Points
Section titled “Access Points”An EFS access point is an application-specific entry point into an EFS file system that makes it easier to manage application access to shared datasets. Access points can enforce a user identity for all file system requests that are made through the access point, and can also enforce a root directory for the file system.
Terraform Example
Section titled “Terraform Example”The following Terraform code will create a new EFS file system and a mount target in a specified subnet.
# main.tf - Example for creating an EFS file system
variable "subnet_id" { description = "The ID of the subnet to create the mount target in" type = string}
resource "aws_efs_file_system" "shared_storage" { creation_token = "uo-myapp-efs"
tags = { Name = "UO Myapp Shared Storage" Environment = "Production" }}
resource "aws_efs_mount_target" "main" { file_system_id = aws_efs_file_system.shared_storage.id subnet_id = var.subnet_id}Code Explanation
Section titled “Code Explanation”variable "subnet_id": This defines a variable that you can use to pass the ID of the subnet to your Terraform configuration.resource "aws_efs_file_system" "shared_storage": This block declares a new EFS file system resource. Thecreation_tokenis a unique string that ensures that you don’t accidentally create multiple file systems.resource "aws_efs_mount_target" "main": This block creates a new mount target for the EFS file system in the specified subnet. This allows EC2 instances in that subnet to mount the file system.
Next Steps
Section titled “Next Steps”Now that you have a shared EFS file system, you can start using it with your EC2 instances.
- Learn how to mount your EFS file system on an EC2 instance.
- Explore how to use EFS Access Points to manage application access to your file system.