Guide · AWS DataSync · Amazon EFS
AWS DataSync with EFS for MCP Servers — On-Premises NFS Migration and Cross-Region Replication
Amazon EFS is the most common destination for DataSync transfers in MCP server deployments: you use DataSync to populate a new EFS file system with an existing dataset (from S3, an on-premises NFS share, or another EFS in a different region) faster than a manual copy inside a container. The key operational detail is that DataSync does not mount EFS itself — it creates an ENI inside a subnet you specify, and all file I/O flows through that ENI. This guide covers every parameter of CreateLocationEfsCommand, the two-SG chain required for DataSync ENI → EFS access, EFS access point integration, and the on-premises NFS agent activation flow for hybrid MCP deployments.
TL;DR
The most common DataSync + EFS mistake is getting the security group chain wrong. DataSync creates a network interface (ENI) in Ec2Config.SubnetArn using Ec2Config.SecurityGroupArns. That security group must have an outbound rule allowing TCP 2049 to the EFS security group. The EFS security group must have an inbound rule allowing TCP 2049 from the DataSync ENI security group. Without this exact chain, the task execution hangs in LAUNCHING for about 60 seconds then fails with CANNOT_CONNECT_TO_DESTINATION.
When to use DataSync to populate EFS (vs alternatives)
DataSync is the right tool for initial EFS population in three situations:
- Large existing S3 dataset — You have 50 GB+ of files in S3 and need them pre-loaded into EFS before your MCP server containers start. DataSync does this in parallel using multiple worker threads within its managed infrastructure, faster than streaming through a Lambda or container.
- On-premises NFS migration — You run MCP server tooling on-premises against an NFS mount. You are lifting to AWS and need to migrate that file tree to EFS preserving POSIX permissions (uid/gid, mode bits, timestamps) — DataSync preserves all of these;
aws s3 cpdoes not. - Cross-region EFS replica — You need a secondary EFS in another region for DR. EFS native replication gives you a continuous read-only replica; DataSync gives you a schedulable, differential sync to a writable EFS — the tradeoff is higher RPO but the destination is writable (you can fail over to it).
DataSync is not the right choice for ongoing file sync between EFS and your application. For that, mount the EFS file system directly inside your ECS task or Lambda function using the EFS FileSystemConfigs pattern.
CreateLocationEfsCommand — full parameter reference
import {
DataSyncClient,
CreateLocationEfsCommand,
} from "@aws-sdk/client-datasync";
const datasync = new DataSyncClient({ region: "us-east-1" });
const efsLoc = await datasync.send(new CreateLocationEfsCommand({
// Required: file system ARN (not the mount target ARN)
EfsFilesystemArn:
"arn:aws:elasticfilesystem:us-east-1:123456789012:file-system/fs-0abc123def",
// Required: subnet and security group for the DataSync ENI
Ec2Config: {
SubnetArn:
"arn:aws:ec2:us-east-1:123456789012:subnet/subnet-0aaaabb111",
SecurityGroupArns: [
"arn:aws:ec2:us-east-1:123456789012:security-group/sg-datasync-eni",
],
},
// Optional: path within EFS to scope the transfer (default: /)
Subdirectory: "/mcp-models/",
// Required when using IAM authorization (FileSystemAccessRoleArn):
InTransitEncryption: "TLS1_2",
// Optional: scope to a specific EFS access point
// AccessPointArn:
// "arn:aws:elasticfilesystem:us-east-1:123456789012:access-point/fsap-0xyz",
// Optional: use IAM authorization (requires InTransitEncryption: TLS1_2)
// FileSystemAccessRoleArn:
// "arn:aws:iam::123456789012:role/datasync-efs-iam-auth",
}));
console.log(efsLoc.LocationArn);
The Subdirectory must start with / and must exist in the EFS file system before you create the location. DataSync does not create directories. If the directory does not exist, the task execution fails with MKDIR_FAILED at the destination.
Security group chain: DataSync ENI → EFS
DataSync creates a network interface in the specified subnet using the specified security group. All NFS traffic (TCP 2049) flows from this ENI to the EFS mount target ENIs. You need exactly two security group rules:
Step 1: DataSync ENI security group — outbound
# sg-datasync-eni: allow outbound TCP 2049 to EFS SG
aws ec2 authorize-security-group-egress \
--group-id sg-datasync-eni \
--ip-permissions '[{
"IpProtocol": "tcp",
"FromPort": 2049,
"ToPort": 2049,
"UserIdGroupPairs": [{"GroupId": "sg-efs"}]
}]'
Step 2: EFS security group — inbound
# sg-efs: allow inbound TCP 2049 from DataSync ENI SG
aws ec2 authorize-security-group-ingress \
--group-id sg-efs \
--ip-permissions '[{
"IpProtocol": "tcp",
"FromPort": 2049,
"ToPort": 2049,
"UserIdGroupPairs": [{"GroupId": "sg-datasync-eni"}]
}]'
You do not need to allow inbound on sg-datasync-eni — NFS is a client-initiated protocol and AWS tracks connection state. The DataSync ENI SG also does not need an outbound rule to 0.0.0.0/0; a targeted rule to sg-efs is sufficient and more secure.
Important: the Ec2Config.SubnetArn must be in the same AZ as at least one EFS mount target. If there is no mount target in that AZ, DataSync cannot reach the EFS file system and the execution hangs in LAUNCHING.
EFS access point integration
When you specify AccessPointArn, DataSync mounts through the access point, inheriting its POSIX UID/GID override and root directory. This is useful for isolating DataSync's writes to a specific subdirectory of a shared EFS file system without granting it access to other paths.
// EFS access point for DataSync: restricts writes to /mcp-models/ and enforces UID/GID 1001
const efsLocWithAP = await datasync.send(new CreateLocationEfsCommand({
EfsFilesystemArn:
"arn:aws:elasticfilesystem:us-east-1:123456789012:file-system/fs-0abc123",
Ec2Config: {
SubnetArn: "arn:aws:ec2:us-east-1:123456789012:subnet/subnet-0aaa",
SecurityGroupArns: ["arn:aws:ec2:us-east-1:123456789012:security-group/sg-datasync"],
},
AccessPointArn:
"arn:aws:elasticfilesystem:us-east-1:123456789012:access-point/fsap-0mcp-models",
FileSystemAccessRoleArn:
"arn:aws:iam::123456789012:role/datasync-efs-iam-auth",
InTransitEncryption: "TLS1_2",
// Subdirectory is relative to the access point's RootDirectory
Subdirectory: "/",
}));
When AccessPointArn is set, FileSystemAccessRoleArn and InTransitEncryption: TLS1_2 are required. If you omit either, you get InvalidRequestException: AccessPointArn requires FileSystemAccessRoleArn and InTransitEncryption: TLS1_2.
The FileSystemAccessRoleArn IAM role must have elasticfilesystem:ClientMount and elasticfilesystem:ClientWrite on the file system ARN (and optionally the access point ARN with a Condition.StringEquals on elasticfilesystem:AccessPointArn for precise scoping). The role trust policy must allow datasync.amazonaws.com to assume it.
POSIX metadata preservation
Unlike S3, EFS is a full POSIX file system — files have uid, gid, mode bits, atime, and mtime. DataSync preserves all of these when transferring between NFS/EFS sources and EFS destinations.
await datasync.send(new CreateTaskCommand({
SourceLocationArn: nfsSourceArn,
DestinationLocationArn: efsDestArn,
Options: {
// Preserve modification time (default: PRESERVE)
Mtime: "PRESERVE",
// Preserve access time (best-effort — S3 sources cannot provide atime)
Atime: "BEST_EFFORT",
// Preserve numeric UID and GID values
Uid: "INT_VALUE",
Gid: "INT_VALUE",
// Preserve Unix permission bits (rwxrwxrwx)
PosixPermissions: "PRESERVE",
// Don't delete files at destination that were deleted at source
PreserveDeletedFiles: "PRESERVE",
// For NFS→EFS: also transfer device nodes and symlinks
PreserveDevices: "NONE", // EFS doesn't support device files
// Transfer sparse files as sparse (saves space on destination)
TransferMode: "CHANGED",
},
}));
PreserveDevices: "NONE" is mandatory for EFS destinations — EFS does not support character or block device files. If your source NFS has device files and you use PreserveDevices: "PRESERVE", those files will cause UNSUPPORTED_FILE_TYPE errors.
On-premises NFS to EFS: DataSync agent setup
To transfer from an on-premises NFS server (or any NFS server not in your VPC), you deploy a DataSync agent. The agent is a lightweight VM that runs in your on-premises environment or on an EC2 instance, and it communicates with the DataSync control plane over HTTPS.
Agent deployment options
- VMware OVA — download from the DataSync console and deploy on a vSphere host close to the NFS server
- KVM image — same OVA as VMware, importable on KVM/QEMU
- EC2 AMI — deploy in an EC2 instance in your VPC (useful when transferring between a bastion-accessible NFS share and EFS in the same VPC)
- Bare metal** — AWS provides scripts for installing the agent on bare-metal hosts running Amazon Linux 2 or RHEL/CentOS
Activation flow
// 1. After deploying the agent VM, it listens on port 80 for activation
// 2. Get the activation key (browser-based or curl):
// curl "http:///?gatewayType=SYNC&activationRegion=us-east-1&no_redirect"
// → returns a 29-character activation key like: AAAA1-BBBBB-2CCCCC-3DDDDD-EEEEE
// 3. Register the agent in AWS DataSync:
import { CreateAgentCommand } from "@aws-sdk/client-datasync";
const agent = await datasync.send(new CreateAgentCommand({
ActivationKey: "AAAA1-BBBBB-2CCCCC-3DDDDD-EEEEE",
AgentName: "mcp-on-prem-nfs-agent",
Tags: [{ Key: "project", Value: "mcp-server" }],
}));
console.log(agent.AgentArn); // arn:aws:datasync:us-east-1:123456789012:agent/agent-xxx
Creating an NFS source location with the agent
import { CreateLocationNfsCommand } from "@aws-sdk/client-datasync";
const nfsLoc = await datasync.send(new CreateLocationNfsCommand({
// On-premises NFS server hostname or IP
ServerHostname: "nfs-server.internal.example.com",
// NFS export path on the server
Subdirectory: "/exports/mcp-tools/",
// Registered DataSync agent that can reach the NFS server
OnPremConfig: {
AgentArns: [agent.AgentArn],
},
// NFS mount options (defaults to NFS4_1 — most compatible)
MountOptions: {
Version: "NFS4_1",
},
}));
The agent must be able to reach the NFS server on TCP/UDP 2049 (and TCP 111 for portmapper on NFSv3). The agent communicates with the DataSync control plane on HTTPS port 443 — ensure outbound 443 is open from the agent host.
Cross-region EFS replication via DataSync
EFS native replication provides a continuous, read-only replica. DataSync provides a schedulable, writable replica — useful when you want to fail over to the secondary EFS and resume writes without promoting a read-only replica.
// Two EFS locations in different regions — both created in us-east-1 DataSync control plane
// (DataSync tasks are regional; create the task in the source region)
const datasyncEast = new DataSyncClient({ region: "us-east-1" });
const datasyncWest = new DataSyncClient({ region: "us-west-2" });
// Source: EFS in us-east-1
const sourceEfs = await datasyncEast.send(new CreateLocationEfsCommand({
EfsFilesystemArn:
"arn:aws:elasticfilesystem:us-east-1:123456789012:file-system/fs-east",
Ec2Config: {
SubnetArn: "arn:aws:ec2:us-east-1:123456789012:subnet/subnet-east",
SecurityGroupArns: ["arn:aws:ec2:us-east-1:123456789012:security-group/sg-east-datasync"],
},
InTransitEncryption: "TLS1_2",
}));
// Destination: EFS in us-west-2
// IMPORTANT: Cross-region EFS location must be created with the us-west-2 EFS ARN,
// but you create it using the us-east-1 DataSync client (where the task will run).
// DataSync in us-east-1 can reach EFS in us-west-2 via its internal network.
const destEfs = await datasyncEast.send(new CreateLocationEfsCommand({
EfsFilesystemArn:
"arn:aws:elasticfilesystem:us-west-2:123456789012:file-system/fs-west",
Ec2Config: {
// Subnet in us-west-2 where DataSync will create its ENI to reach the EFS
SubnetArn: "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-west",
SecurityGroupArns: ["arn:aws:ec2:us-west-2:123456789012:security-group/sg-west-datasync"],
},
InTransitEncryption: "TLS1_2",
}));
Cross-region data transfer via DataSync costs the standard DataSync rate ($0.0125/GB) plus the inter-region data transfer cost (~$0.02/GB for us-east-1 → us-west-2). For a 100 GB EFS sync, that is about $3.25 total. EFS native replication is typically cheaper for continuous sync but requires you to pay for a full read-only replica file system at standard EFS rates.
Cost comparison: DataSync vs alternatives for EFS population
| Method | 100 GB initial population cost (approximate) | POSIX metadata preserved | Time for 100 GB |
|---|---|---|---|
| DataSync (S3→EFS) | $1.25 DataSync + $0 inter-region (same region) + minimal S3 GET fees ≈ $1.30 | Partial (uid/gid from object metadata headers) | 5–15 min at 100 Mbps DataSync |
| DataSync (NFS→EFS) | $1.25 + agent EC2 cost (t3.medium ~$0.04/hr) ≈ $1.30 | Full (uid, gid, mtime, permissions) | Depends on network speed; ~15 min at 1 Gbps |
| rsync inside a container | Fargate/EC2 compute cost + ECS task overhead ≈ $0.10–0.50 (depending on task size) | Full (rsync -a preserves all) | Longer; single-threaded for small files |
| aws s3 cp --recursive in Lambda | Lambda compute: 15 min × 2 vCPU × 4 invocations ≈ $0.20; S3 request fees ≈ $0.10 | None (S3 objects have no POSIX metadata by default) | Parallelizable but limited by Lambda timeout and memory |
For large files (each file >100 MB), rsync inside an ECS Fargate task is often competitive with DataSync. DataSync's advantage is clearest for datasets with millions of small files, where its parallel worker design significantly outperforms single-threaded rsync.
Common DataSync + EFS errors and fixes
| Error / symptom | Cause | Fix |
|---|---|---|
Execution stuck in LAUNCHING then fails with CANNOT_CONNECT_TO_DESTINATION |
Missing outbound TCP 2049 from DataSync ENI SG to EFS SG, or no EFS mount target in the specified AZ | Add outbound TCP 2049 from DataSync ENI SG to EFS SG; verify there is a mount target in the same AZ as Ec2Config.SubnetArn |
MKDIR_FAILED during LAUNCHING |
Subdirectory does not exist in the EFS file system |
Create the directory first: mount EFS in a container and run mkdir -p /mnt/efs/mcp-models/ |
InvalidRequestException: AccessPointArn requires FileSystemAccessRoleArn |
Specified AccessPointArn without FileSystemAccessRoleArn and InTransitEncryption: TLS1_2 |
Always set both FileSystemAccessRoleArn and InTransitEncryption: TLS1_2 when using an access point |
UNSUPPORTED_FILE_TYPE for device files |
Source NFS has character/block device files; EFS does not support these | Set Options.PreserveDevices: "NONE" (the default) — DataSync will skip device files |
| Files transferred but uid/gid are wrong at destination | Options.Uid or Options.Gid set to NONE (the default for S3→EFS), causing DataSync to use the DataSync agent's UID (usually 0 = root) |
Set Uid: "INT_VALUE" and Gid: "INT_VALUE" to preserve numeric ownership. For S3 sources, also set custom metadata headers on S3 objects (x-amz-meta-uid, x-amz-meta-gid) before the transfer |
Related guides
- AWS DataSync overview: tasks, locations, and execution lifecycle
- DataSync with S3: storage classes, filter patterns, and cross-account copies
- DataSync with FSx: Lustre, Windows, ONTAP, and OpenZFS location types
- Amazon EFS for MCP Servers: shared persistent storage, mount targets, and access points
- EFS with Lambda: FileSystemConfigs, cold start latency, and VPC configuration
- EFS performance modes: Bursting, Elastic, and Provisioned throughput
- MCP server uptime monitoring