Learning center

ECS ResourceInitializationError mounting an EFS volume

Compare the NFS client's Availability Zone and security group with the file system's mount targets before you touch IAM. The client is the task on Fargate and the container instance on EC2. If a mount target in that zone accepts NFS on TCP 2049 from the client, and the subnets' network ACLs and the VPC's DNS settings let the connection through, the failure is in the revision's authorizationConfig, the IAM policies or the transit encryption settings.

The signature and its nearby causes#

A deployment adds or changes an EFS volume, and its tasks stop with stop code TaskFailedToStart and a stopped reason that begins ResourceInitializationError and says the EFS volume could not be set up. The containers never ran. On Fargate, a supervisor container that the platform creates manages the volume, so the mount happens outside your image. Task fields · ResourceInitializationError troubleshooting · EFS volumes with ECS

Three layers sit between the task and the files:

  • The NFS path. EFS DNS names resolve only when the file system has a mount target in the client's Availability Zone, and the mount target's security group must allow inbound NFS on TCP 2049 from the client's security group: the task's on Fargate, the container instance's on EC2.
  • Authorization. With iam set to ENABLED, ECS mounts with the task role, and EFS evaluates that role together with the file system policy. An access point adds its own root directory and POSIX identity.
  • Transit encryption. IAM authorization and access points both require transitEncryption set to ENABLED, and a file system policy can refuse clients that do not encrypt.

EFS DNS names · EFS security groups · ECS EFS best practices · EFSVolumeConfiguration

When the stopped reason carries the mount helper's output, AWS's troubleshooting article sorts it into the same layers: a connection timeout points at security groups or routing, a failure to resolve the file system's name points at DNS or a missing mount target, and an access-denied result points at IAM or the file system policy. Use the output to choose where to start, and the reads below to confirm it. Fargate EFS mount issues · EFS mount troubleshooting

Read the task and the volume configuration#

Use a read-only profile and replace the uppercase placeholders. Save the stopped task within an hour of the failure, while ECS still returns it. Stopped task retention

aws ecs describe-tasks \
  --profile PROFILE --region REGION --cluster CLUSTER --tasks TASK_ARN \
  --query 'tasks[].{task:taskArn,definition:taskDefinitionArn,deployment:startedBy,launchType:launchType,containerInstance:containerInstanceArn,code:stopCode,reason:stoppedReason,az:availabilityZone,platform:platformVersion,taskRoleOverride:overrides.taskRoleArn,eni:attachments[?type==`ElasticNetworkInterface`].details}' \
  --output json --no-cli-pager

aws ecs describe-task-definition \
  --profile PROFILE --region REGION --task-definition TASK_DEFINITION_ARN \
  --query 'taskDefinition.{definition:taskDefinitionArn,taskRole:taskRoleArn,efs:volumes[?efsVolumeConfiguration].{volume:name,config:efsVolumeConfiguration},mounts:containerDefinitions[].{container:name,mountPoints:mountPoints}}' \
  --output json --no-cli-pager

Note launchType, az, the subnet in the interface details, and from the volume configuration the fileSystemId, rootDirectory, transitEncryption, transitEncryptionPort, and authorizationConfig.accessPointId and iam. The task role that matters is taskRoleOverride when it is set, otherwise taskRole. The execution role does not mount EFS volumes. EFSAuthorizationConfig · Task overrides

The launch type decides which network the NFS client uses. On Fargate the mount goes out through the task's own interface, so the checks below use the task's subnet and security groups. On EC2, ECS mounts the volume on the container instance, so the client is the instance: AWS's EC2 tutorial admits the container instances' security group on the mount target. Read the instance's subnet, zone and groups, and use them in place of the task's below. EFS tutorial for ECS

aws ecs describe-container-instances \
  --profile PROFILE --region REGION --cluster CLUSTER --container-instances CONTAINER_INSTANCE_ARN \
  --query 'containerInstances[].ec2InstanceId' --output text --no-cli-pager

aws ec2 describe-instances \
  --profile PROFILE --region REGION --instance-ids INSTANCE_ID \
  --query 'Reservations[].Instances[].{az:Placement.AvailabilityZone,subnet:SubnetId,groups:SecurityGroups[].GroupId}' \
  --output json --no-cli-pager

Check the NFS path first#

List the mount targets and the security groups on the one in the client's zone:

aws efs describe-mount-targets \
  --profile PROFILE --region REGION --file-system-id FILE_SYSTEM_ID \
  --query 'MountTargets[].{id:MountTargetId,az:AvailabilityZoneName,subnet:SubnetId,state:LifeCycleState,ip:IpAddress}' \
  --output json --no-cli-pager

aws efs describe-mount-target-security-groups \
  --profile PROFILE --region REGION --mount-target-id MOUNT_TARGET_ID \
  --query 'SecurityGroups' --output json --no-cli-pager

aws ec2 describe-security-groups \
  --profile PROFILE --region REGION --group-ids MOUNT_TARGET_SECURITY_GROUP_ID \
  --query 'SecurityGroups[].{id:GroupId,nfs:IpPermissions[?FromPort<=`2049` && ToPort>=`2049` || IpProtocol==`"-1"`].{protocol:IpProtocol,from:FromPort,to:ToPort,groups:UserIdGroupPairs[].GroupId,cidrs:IpRanges[].CidrIp}}' \
  --output json --no-cli-pager

describe-mount-targets · describe-mount-target-security-groups · describe-security-groups

A file system has at most one mount target per Availability Zone, and a One Zone file system has exactly one. If no available mount target matches the task's az, the file system's DNS name cannot resolve from that zone, which is the failure AWS associates with a missing mount target. If the zone has one, the nfs rules must name the client's security group, or a CIDR that covers the client's address. On Fargate, read the task's security groups from the failed deployment's networkConfiguration; on EC2, use the container instance's groups from above. Check that their outbound rules allow TCP 2049 to the mount target.

Security groups are stateful, but network ACLs are not, and DNS is a separate setting. Read both before ruling the path out:

aws ec2 describe-network-acls \
  --profile PROFILE --region REGION \
  --filters Name=association.subnet-id,Values=CLIENT_SUBNET_ID,MOUNT_TARGET_SUBNET_ID \
  --query 'NetworkAcls[].{id:NetworkAclId,subnets:Associations[].SubnetId,rules:Entries[].{n:RuleNumber,out:Egress,action:RuleAction,protocol:Protocol,cidr:CidrBlock,ports:PortRange}}' \
  --output json --no-cli-pager

aws ec2 describe-vpc-attribute \
  --profile PROFILE --region REGION --vpc-id VPC_ID --attribute enableDnsSupport \
  --output json --no-cli-pager

The ACL on each subnet must allow TCP 2049 toward the mount target and the ephemeral ports on the way back, in both directions' rules; rules apply in number order and the first match wins. EFS DNS names resolve only when the VPC has both DNS resolution and DNS hostnames enabled; read enableDnsHostnames with the same command when the mount output says the name did not resolve. Network ACLs · EFS DNS names · CreateMountTarget · EFS security groups · Deployment fields

Then check authorization and encryption#

When the mount target, the security groups, the network ACLs and DNS all allow the connection, compare the volume configuration with the rules ECS documents and with the file system's own policy and access point:

aws efs describe-file-system-policy \
  --profile PROFILE --region REGION --file-system-id FILE_SYSTEM_ID \
  --query 'Policy' --output text --no-cli-pager

aws efs describe-access-points \
  --profile PROFILE --region REGION --access-point-id ACCESS_POINT_ID \
  --query 'AccessPoints[].{id:AccessPointId,fileSystem:FileSystemId,state:LifeCycleState,root:RootDirectory.Path,creation:RootDirectory.CreationInfo,user:PosixUser}' \
  --output json --no-cli-pager

A PolicyNotFound error means the file system has no policy, and EFS then lets any client that can reach a mount target connect without IAM. DescribeFileSystemPolicy · IAM for EFS clients

ReadReading
iam ENABLED or an accessPointId, with transitEncryption absent or DISABLEDThe revision breaks a documented rule: both require transit encryption
accessPointId set and rootDirectory other than /Another documented rule: with an access point, omit rootDirectory or set it to /
Access point belongs to another fileSystem, or is not availableThe revision points at the wrong or a deleted access point
iam ENABLED, the policy grants elasticfilesystem:ClientMount only to other principals, and the task role's own policies do not allow it eitherThe task role is not authorized, for example because the file system policy names only the execution role
Either policy explicitly denies elasticfilesystem:ClientMount to the task roleThe deny wins over any allow
iam DISABLED, and the policy grants access only to named principalsThe mount carries no role to match, so the policy has nothing to allow
Policy denies requests without secure transport, and transitEncryption is DISABLEDThe policy refuses unencrypted clients, whatever the identity

elasticfilesystem:ClientMount gives read-only access, and a container that writes to the volume also needs elasticfilesystem:ClientWrite. For a task role in the file system's account, an allow in either the role's own policies or the file system policy is enough when no statement denies it, so a file system policy that names other principals refuses the task role only if the role's own policies grant nothing. Read the role's policies before you edit the file system policy:

aws iam list-attached-role-policies --profile PROFILE --role-name TASK_ROLE_NAME --output json --no-cli-pager
aws iam list-role-policies --profile PROFILE --role-name TASK_ROLE_NAME --output json --no-cli-pager

The IAM policy simulator gives a direct answer for the identity side: aws iam simulate-principal-policy --policy-source-arn TASK_ROLE_ARN --action-names elasticfilesystem:ClientMount elasticfilesystem:ClientWrite --resource-arns FILE_SYSTEM_ARN. A role in another account needs both an allow in its own policies and a grant in the file system policy. IAM policy evaluation · simulate-principal-policy EFSVolumeConfiguration · IAM for EFS clients · ECS EFS best practices

Two ways checkout:44 can fail#

This fixture is illustrative. The fictional service checkout moves from checkout:43 to checkout:44, which adds an EFS volume receipts on file system fs-0a1b2c through access point fsap-0d4e5f, with transitEncryption and iam both ENABLED. Tasks run on Fargate 1.4.0 in us-east-1.

ReadPath caseAuthorization case
Mount output in the reasonConnection timed outAccess denied
Task azus-east-1bus-east-1b
Mount targetsus-east-1a, us-east-1b, both availableSame
NFS rule on the mount target's groupAllows 2049 from sg-old-tasks onlyAllows 2049 from sg-checkout
Deployment security groupsg-checkout, new in this releasesg-checkout
File system policyGrants ClientMount, ClientWrite to the task roleGrants them to ecsTaskExecutionRole only
Task role's own policiesNo elasticfilesystem actionsNo elasticfilesystem actions

In the path case, the release moved the service to a new security group that the mount target does not accept, so the NFS connection never completes. Add an inbound TCP 2049 rule for sg-checkout on the mount target's group. In the authorization case, the network is open and EFS refuses the identity: with iam enabled the mount presents the task role, the file system policy allows only the execution role, and the task role's own policies allow nothing on EFS. Grant the task role the two actions in either policy. A third variant would show a task in us-east-1c, where no mount target exists; there the fix is a mount target in that zone or removing that zone's subnet from the service.

Confirm on the replacement task#

Record the replacement task's ARN, revision, az and startedAt. A task that reaches RUNNING got past volume setup. Then exercise the mount the way the application does, such as writing and reading back a file under the container path, because a read-only grant or an access point's POSIX user can still refuse writes after a successful mount. If the service spans several zones, confirm a replacement in each one, since each zone uses its own mount target.

Where this reading stops#

The rules read now may not be the rules the task met. A security group or policy edited during the incident hides the original cause, so save the stopped reason before changing anything. Treat the helper's text in the reason as a pointer to a layer, not a fixed code. Check platform support before the layers above: on Fargate, EFS volumes need Linux platform version 1.4.0 or later, and on EC2, access points and IAM authorization need container agent 1.38.0 or later, with amazon-efs-utils and the ECS volume plugin on a custom AMI. EFS volumes with ECS

Other startup failures share this stop code and reason prefix. If the reason names a log group or a secret instead, see the missing log group guide or the secrets guide, and the signature table for the rest.

Questions#

Which IAM role does ECS use to mount an EFS volume?

With iam set to ENABLED in the volume's authorizationConfig, ECS passes the task role, or a task role override, to EFS. The execution role is not used for the mount. A file system policy that names only the execution role refuses the mount unless the task role's own policies allow elasticfilesystem:ClientMount.

What security group rule does an EFS mount target need for ECS tasks?

An inbound rule for NFS on TCP 2049 on the security group attached to the mount target, from the task's security group on Fargate or the container instance's on EC2. The client's group must also allow that traffic outbound.

Why does an EFS mount fail in only one Availability Zone?

EFS DNS names resolve only when the file system has a mount target in the client's zone. A service whose subnets span a zone without a mount target fails there and works in the others.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading