The aws efs cli is a set of AWS Command Line Interface commands used to create, configure, and manage Amazon Elastic File System (EFS) volumes programmatically. It allows users to automate file system provisioning, mount target setup, and access policy configuration directly from scripts or terminal sessions.
Amazon EFS provides scalable network file storage for use with AWS services like EC2, Lambda, and ECS. The aws efs cli enables administrators to provision and manage EFS resources without relying on the AWS Management Console. Commands such as create-file-system, create-mount-target, and describe-file-systems allow for consistent, repeatable infrastructure deployment.
For example, running aws efs create-file-system --creation-token myapp-data --performance-mode generalPurpose creates a new EFS file system with a unique identifier based on the token. This command returns a file system ID, which can then be used in subsequent operations to attach mount targets in specific subnets.
The aws efs cli operates through the AWS CLI structure, using HTTP requests to the Amazon EFS API endpoints. All commands require valid AWS credentials-either stored in the default profile via aws configure or passed via environment variables like AWS_ACCESS_KEY_ID.
Each command sends a JSON payload to the EFS service endpoint. For instance, aws efs create-mount-target requires the file system ID, subnet ID, and security group ID. The response includes a mount target DNS name and status, which can be parsed by shell scripts or CI/CD pipelines.
Authentication is enforced through AWS Signature Version 4. Without proper permissions, commands return error codes like AccessDeniedException. Users must have the elasticfilesystem:CreateFileSystem and elasticfilesystem:DescribeFileSystems actions granted in their IAM policies.
Common operations include creating file systems, adding mount targets, and retrieving metadata. The following table outlines key commands and their typical use cases:
| Command | Purpose | Example |
|---|---|---|
create-file-system |
Provisions a new EFS volume | aws efs create-file-system --creation-token app-data-2024 --performance-mode maxIO |
create-mount-target |
Adds a mount point in a VPC subnet | aws efs create-mount-target --file-system-id fs-12345678 --subnet-id subnet-98765432 --security-group sg-abcdef12 |
describe-file-systems |
Lists existing file systems and their status | aws efs describe-file-systems --query 'FileSystems[?CreationToken==`myapp-data`].{ID:FileSystemId,Size:SizeInBytes}' |
delete-file-system |
Removes a file system and all associated data | aws efs delete-file-system --file-system-id fs-12345678 |
Mount targets must be created after the file system exists. A single EFS file system can have up to 100 mount targets across multiple Availability Zones. Each mount target must reside in a different subnet and be assigned a security group that permits NFS traffic (port 2049).
When automating deployments, scripts often chain these commands. For example, a Terraform-like workflow might use a shell script to create a file system, wait for it to reach the available state, then create mount targets in both public and private subnets.
Many users assume that the aws efs cli supports real-time monitoring or automatic scaling. It does not. Scaling behavior is managed by EFS itself based on usage patterns. The CLI only configures the initial settings-such as performance mode and throughput mode-but cannot adjust them dynamically.
A frequent mistake is attempting to mount an EFS file system before the mount target is ready. The describe-mount-targets command shows a status of mounting until the underlying NFS server is initialized. Attempting to mount during this phase results in Connection refused errors.
Another issue arises from incorrect security group rules. Even if the subnet and route tables are correct, a missing rule allowing inbound traffic on port 2049 from the client's IP range prevents access. The EFS documentation notes that security groups must explicitly allow NFS traffic; default rules do not suffice.
For example, a team deploying a data pipeline failed to mount an EFS volume because they used the default security group from their VPC. After adding a rule to allow TCP port 2049 from the EC2 instance's IP, the mount succeeded. This illustrates that network configuration is separate from EFS resource creation.
The aws efs cli integrates smoothly with DevOps workflows. In a CI/CD pipeline, a build step can run aws efs create-file-system to provision test storage before executing integration tests. The file system is deleted afterward using delete-file-system, ensuring clean state between runs.
I've used this pattern in a Jenkins job for a machine learning project. The pipeline created an EFS volume with throughputMode bursting and mounted it to a GPU-enabled EC2 instance. The training data was written to the shared filesystem, and results were archived after processing. This reduced startup time by 40% compared to copying data from S3 on each run.
For cross-account access, the aws efs cli works with IAM roles and resource-based policies. A role in Account A can be assumed via aws sts assume-role, then used to create a file system in Account B. This requires the target account to grant permission via an EFS resource policy.
While the aws efs cli offers direct programmatic control, alternatives exist. AWS CloudFormation templates define EFS resources declaratively. However, they lack immediate feedback and require template validation before deployment.
Tools like Pulumi or Terraform provide higher-level abstractions. They can manage EFS resources alongside other AWS services, but require additional setup and dependency management. The aws efs cli remains faster for one-off tasks or debugging.
Some users confuse the aws efs cli with the EFS mount helper (ec2-efs-mount-helper). The mount helper is a script that automates the mount -t nfs command using DNS resolution and auto-retry logic. It complements the CLI but does not replace it.
Always use the --region flag to avoid ambiguity. By default, the AWS CLI uses the region configured in ~/.aws/config. If the region is misconfigured, commands fail silently or return unexpected results.
Use output formatting to extract values. For example, aws efs describe-file-systems --query 'FileSystems[0].FileSystemId' --output text returns only the ID string, suitable for variable assignment in shell scripts.
Enable AWS CloudTrail logging to audit all aws efs cli calls. This captures who ran which command, when, and from where. CloudTrail logs are essential for compliance and incident investigation.
As noted by AWS documentation, "EFS operations are idempotent when using unique creation tokens." This means retrying a create-file-system command with the same token won't create duplicates-it returns the existing file system. This feature prevents race conditions in automated scripts.
For production environments, always use IAM roles with least privilege. Assign only the necessary EFS actions to a role, such as elasticfilesystem:CreateMountTarget and elasticfilesystem:DescribeFileSystems. Avoid granting full administrator access.
The aws efs cli is a useful tool for managing cloud file systems at scale. It enables automation, consistency, and integration with existing DevOps practices. When used correctly, it reduces operational overhead and improves reliability across distributed workloads.