Amazon Elastic File System (Amazon EFS) provides simple, scalable file storage for use with your Amazon ECS tasks. With Amazon EFS, storage capacity is elastic, growing and shrinking automatically as you add and remove files. Your applications can have the storage they need, when they need it.
You can use Amazon EFS file systems with Amazon ECS to access file system data across your fleet of Amazon ECS tasks. That way, your tasks have access to the same persistent storage, no matter the infrastructure or container instance on which they land. When you reference your Amazon EFS file system and container mount point in your Amazon ECS task definition, Amazon ECS takes care of mounting the file system in your container. The following sections help you get started using Amazon EFS with Amazon ECS.
This feature is supported by tasks that use both the EC2 and Fargate launch types, however this tutorial will use an Amazon ECS task that uses the Fargate launch type. This tutorial is also meant to be followed step by step, however if you already have some of these resources created on your account then you may be able to skip some steps.
The following resolution applies to the Fargate platform version 1.4.0 or later, which has persistent storage that you can define at the task and container level in Amazon ECS. Fargate platform versions 1.3.0 or earlier don’t support persistent storage using Amazon EFS.
Amazon EFS may not be available in all Regions. For more information about which Regions support Amazon EFS, see Amazon Elastic File System Endpoints and Quotas in the AWS General Reference.
Before you complete the steps , you must have the following:
Create and configure an Amazon EFS file system
- Create an Amazon EFS file system, and then note the EFS ID and security group ID.
Note: Your Amazon EFS file system, Amazon ECS cluster, and Fargate tasks must all be in the same VPC.
To allow inbound connections on port 2049 (Network File System, or NFS) from the security group associated with your Fargate task or service, edit the security group rules of your EFS file system.
Update the security group of your Amazon ECS service to allow outbound connections on port 2049 to your Amazon EFS file system’s security group.
Create a task definition
Open the Amazon ECS console.
From the navigation pane, choose Task Definitions, and then choose Create new Task Definition.
In the Select launch type compatibility section, choose FARGATE, and choose Next Step.
In the Configure task and container definitions section, for Task Definition Name, enter a name for your task definition.
In the Volumes section, choose Add volume.
For Name, enter a name for your volume.
For Volume type, enter EFS.
For File system ID, enter the ID for your Amazon EFS file system.
Note: You can specify custom options for Root directory, Encryption in transit, and EFS IAM authorization. Or, you can accept the default, where “/” is the root directory.
- Choose Add.
In the Containers Definition section, choose Add container.
In the STORAGE AND LOGGING section, in the Mount points sub-section, select the volume that you created for Source volume in step 5.
For Container path, choose your container path.
(Optional) In the ENVIRONMENT section, for Entry point, enter your entry point.
For Command, enter the [df ,-h] command to display the mounted file system.
Note: You can use the entry point and command to test if your Amazon EFS file system is mounted successfully. By default, the container exits after the df -h command executes successfully.
Choose Add.
Fill out the remaining fields in the task definition wizard, and then choose Create.
Run a Fargate task and check your task logs
- Run a Fargate task using the task definition that you created earlier.
Important: Be sure to run your task on the Fargate platform version 1.4.0.
- To verify that your Amazon EFS file system is successfully mounted to your Fargate container, check your task logs.
The output of df-h looks similar to the following:
Top comments (0)