惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Last Week in AI
Last Week in AI
U
Unit 42
博客园 - 【当耐特】
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
Martin Fowler
Martin Fowler
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
美团技术团队
雷峰网
雷峰网
小众软件
小众软件
G
Google Developers Blog
GbyAI
GbyAI
Jina AI
Jina AI
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
F
Fortinet All Blogs
Vercel News
Vercel News

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Cross-region data transfer from NFS server to Amazon EFS ...
Mawuli Dente · 2026-04-28 · via DEV Community

Overview

This AWS DataSync solution transfers data from an EC2-hosted NFS share in VPC A (us-east-1) to an Amazon EFS file system in VPC B (us-west-2). The two VPCs are connected through a peering connection. This setup simulates a typical on-premises to cloud data migration scenario.

An NFS server uses the NFS protocol to share files and directories over a network.

Amazon EFS is a fully managed, serverless cloud file storage service that provides elastic, shared file storage for Linux-based workloads and applications running on AWS services like EC2.

AWS DataSync, a fully managed, high-speed data transfer service, communicates with both storage locations via VPC endpoints, utilizing a private, fast and secure connection to accomplish the transfer.

VPC Endpoints provide private interface entry points to AWS services from within a VPC. While many AWS services have public endpoints that can be accessed over the internet, it is a best practice to use VPC endpoints to communicate with AWS services securely from within a VPC.

Architecture Diagram

extra-large Architecture diagram

US-EAST-1

VPC A

  1. Create a VPC A in us-east-1 with 10.0.0.0/16 Cidr.
  2. Create two public subnets and an internet gateway.
  3. Create two private subnets and a nat gateway.
  4. Create an SSM Endpoint security group with the following rules:
    1. Inbound: 
      1. HTTPS from VPC A.
    2. Outbound
      1. All traffic to VPC A.
  5. Set up SSM Default Host Management Configuration to enable Session Manager to access the NFS server. You can optionally use a bastion host to access the NFS server.
  6. Use the default Host Management role or create and attach an EC2 role to the NFS server for session manager to work. Attach the following AWS managed policies to the EC2 role:
    1. AmazonSSMManagedEC2InstanceDefaultPolicy
    2. AmazonSSMManagedInstanceCore

extra-large Architecture diagram

VPC A Endpoints

Create a VPC endpoint each for SSMEC2-Messages, and SSM-Messages as follows:

  1. Create endpoint.
  2. Optional name.
  3. Choose “AWS services” type.
  4. Type “ssm” and search.
  5. Select the first option com.amazonaws.us-east-1.ssm. The name varies according to the service.
  6. Next, select VPC A.
  7. Check “Enable private DNS name”.
  8. DNS record IP type: IPv4.
  9. Subnets. Check the first two Availability Zones in the list. Under Subnet ID, select both private subnets.
  10. IP address type: IPv4.
  11. Security groups: Use the SSM Endpoint Security Group created earlier. You will use this security group for all VPC endpoints in region A.
  12. Policy: Full access.

extra-large Architecture diagram

NFS Server

Create the NFS server with the following specifications:

  1. Launch instances.
  2. Amazon Linux AMI.
  3. t2.micro instance type.
  4. Proceed without a key pair.
  5. PrivateSubnetA.
  6. Auto-assign public IP disabled.
  7. Create NFS server security group:
    1. Inbound: 
      1. HTTPS from SSM Endpoint.
      2. NFS from VPC B.
      3. ICMP from VPC B.
    2. Outbound
      1. All traffic to VPC A and B.
  8. 8 GB gp3 EBS volume.
  9. User data for NFS server. Creates and exports NFS share, generates files for the transfer.

#!/bin/bash
set -e
sleep 180
# Check if the secondary drive exists
if ! lsblk /dev/xvdb &>/dev/null; then
    echo “/dev/xvdb not found. Exiting.”
    exit 1
fi

mkfs.ext4 /dev/xvdb
mkdir -p /mnt/data
mount /dev/xvdb /mnt/data
echo ‘/dev/xvdb /mnt/data ext4 defaults,nofail 0 2’ | sudo tee -a /etc/fstab

# Create and set up NFS share directory
TARGET_DIR=”/mnt/data/nfs_share”
PREFIX=”test”
EXT=”.txt”
mkdir -p $TARGET_DIR
chown -R nobody:nobody $TARGET_DIR
chmod 777 $TARGET_DIR

# Function to generate files
generate_files() {
local start=$1
local end=$2
local size_range=$3
local block_size=$4
local group_label=$5

local start_time=$(date +%s)
echo “Starting generation of $group_label at $(date)for i in $(seq -f “%04g” $start $end); do
    FILE=${TARGET_DIR}/${PREFIX}${i}${EXT}SIZE=$((RANDOM % size_range + 1))
    dd if=/dev/urandom of=$FILEbs=$block_size count=$SIZE status=none &
done
wait

local end_time=$(date +%s)
echo “Finished generation of $group_label at $(date)local elapsed_time=$((end_time - start_time))
echo “Time taken for $group_label: ${elapsed_time} seconds”
}

# Generate file groups with time tracking
generate_files 1 1000 100 1K “1000 files (1KB to 100KB)” &
generate_files 1001 1100 100 1M “100 files (1MB to 100MB)” &

wait
echo “File generation complete in $TARGET_DIRsed -i\|^$TARGET_DIR |d” /etc/exports
echo$TARGET_DIR *(rw,sync,no_root_squash,no_all_squash)” | sudo tee -a /etc/exports > /dev/null
systemctl start nfs-server
systemctl enable nfs-server
exportfs -rav

Enter fullscreen mode Exit fullscreen mode

Verify that you can connect to the NFS server via Session Manager.

US-WEST-2

VPC B

  1. Create a target VPC in us-west-2 with 172.31.0.0/16 Cidr.
  2. Create two public subnets and an internet gateway.
  3. Create two private subnets and a NAT gateway.
  4. Follow the same steps as in Region A to enable Session Manager to access the NFS client.
  5. Create and attach an SSM Endpoint Security Group to all the endpoints:

    1. Inbound: 
      1. HTTPS from DataSync agent.
      2. NFS from VPC B.
      3. 1024 – 1064 from DataSync agent.
    2. Outbound
      1. All traffic to VPC B.
  6. Attach the same EC2 role created from VPC A to the NFS client if you are in the same account. For different accounts, you need to create a new EC2 role for the NFS client.

  7. Create and attach an EC2 role to the DataSync agent. Attach the following AWS managed policies to the role:

    1. AWSDataSyncFullAccess
    2. AmazonSSMManagedEC2InstanceDefaultPolicy
    3. AmazonSSMManagedInstanceCore

DataSync Agent

Create the DataSync agent using the specifications below:

  1. DataSync latest AMI.
  2. t3.micro instance type.
  3. Proceed without a key pair.
  4. PrivateSubnetA.
  5. Auto-assign public IP disabled.
  6. Create a DataSync agent security group as follows:
    1. Inbound: 
      1. HTTPS from VPC B.
      2. HTTP from NFS client.
      3. ICMP from NFS client.
    2. Outbound
      1. All traffic to VPC A and B.
  7. 20 GB gp3 EBS volume.

VPC B Endpoints

Follow similar procedures from US-EAST-1 to create VPC endpoints for:

  1. SSM.
  2. EC2-Messages.
  3. SSM-Messages.
  4. EFS.
  5. DataSync.

extra-large Architecture diagram

NFS Client

Create the NFS client EC2 as shown below:

  1. Launch instances.
  2. Amazon Linux AMI.
  3. t2.micro instance type.
  4. Proceed without a key pair.
  5. PrivateSubnetA.
  6. Create an NFS client security group:
    1. Inbound: 
      1. HTTPS from VPC B.
    2. Outbound
      1. All traffic to VPC A and B.
  7. 8 GB gp3 EBS volume.

EFS file system

  1. Create an EFS Security Group with the following rules:
    1. Inbound: 
      1. NFS traffic from VPC B.
      2. NFS traffic from NFS Client.
      3. NFS traffic from DataSync agent. 
      4. NFS traffic from SSM Endpoint.
      5. HTTPS from VPC B and SSM Endpoint.
      6. ICMP from NFS client.
    2. Outbound
      1. All traffic to VPC B.
  2. Create file system.
  3. Select the target VPC.
  4. Keep the recommended settings and Create file system.
  5. Click on the file system ID.
  6. Go to the Network tab.
  7. Manage.
  8. For the two mount points, edit the security groups to use only the earlier created EFS Security Group.

VPC Peering

  1. Create peering connection.
  2. Optional name.
  3. VPC ID (Requester): VPC A ID.
  4. Select another VPC to peer with: My account.
  5. Region: Another Region.
  6. VPC ID (Accepter): VPC B ID.

extra-large Architecture diagram

  1. From Region B (us-west-2) Peering Connections, select the peering connection available.
  2. From the “Actions” menu, Accept request. Confirm.

extra-large Architecture diagram

  1. Update the private route table for VPC A to forward Region B traffic to the peering connection.

extra-large Architecture diagram

  1. Update the private route table for VPC B to forward Region A traffic to the peering connection.

extra-large Architecture diagram

Systems Setup

Mount the NFS share

Connect to the NFS client via Session Manager.
Mount the NFS share from the NFS client over the peering connection.

# Ping the NFS server to verify connection
ping -c 5 10.0.x.x

# Mount NFS server
sudo mkdir -p /mnt/nfs
sudo mount -t nfs 10.0.x.x:/mnt/data/nfs_share /mnt/nfs -o rw,sync

Enter fullscreen mode Exit fullscreen mode

extra-large Architecture diagram

extra-large Architecture diagram

Mount the EFS file system

Mount the EFS file system from the NFS client.

# Mount EFS file system
sudo mkdir -p /mnt/efs

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-xxxxxxxxxxxxxxx.efs.us-west-2.amazonaws.com:/ /mnt/efs
OR
sudo mount -t nfs4 -o sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport 172.31.x.x:/ /mnt/efs

Enter fullscreen mode Exit fullscreen mode

extra-large Architecture diagram

DataSync agent

Obtain the activation code of the DataSync agent from the NFS client.

# Test connectivity to the agent
nc -vz 172.31.x.x 80 

# Obtain activation code
sudo curl “http://<datasync-agent-ip>/?gatewayType=SYNC&activationRegion=us-west-2&privateLinkEndpoint=<datasync-vpce-ip>&endpointType=PRIVATE_LINK&no_redirect”

# NB: Replace <datasync-agent-ip> and <datasync-vpce-ip> with actual values

Enter fullscreen mode Exit fullscreen mode

Activate the DataSync agent using the activation key.

aws datasync create-agent \
    --agent-name “datasync-agent” \
    --activation-key “xxxxx-xxxxx-xxxxx-xxxxx-xxxxx” \
    --vpc-endpoint-id “vpce-xxxxxxxxxxxxxxxxx” \
    --subnet-arns “arn:aws:ec2:us-west-2:accountId:subnet/subnet-xxxxxxxxxxx” \
    --security-group-arns “arn:aws:ec2:us-west-2:accountId:security-group/sg-xxxxxxxxxxxx”

Enter fullscreen mode Exit fullscreen mode

Create the NFS location.

aws datasync create-location-nfs \
    --server-hostname “10.0.x.x” \
    --subdirectory “/mnt/data/nfs_share” \
    --on-prem-config AgentArns=”arn:aws:datasync:us-west-2:accountId:agent/agent-xxxxxxxxxxx”

Enter fullscreen mode Exit fullscreen mode

Create the EFS location.

aws datasync create-location-efs \
    --efs-filesystem-arn “arn:aws:elasticfilesystem:us-west-2:accountId:file-system/fs-xxxxxxxxxxxxx” \
    --ec2-config SubnetArn=”arn:aws:ec2:us-west-2:accountId:subnet/subnet-xxxxxxxxxxxxx”,SecurityGroupArns=”arn:aws:ec2:us-west-2:accountId:security-group/sg-xxxxxxxxxxxxxxx”

Enter fullscreen mode Exit fullscreen mode

Create a task that connects both locations and start the task.

aws datasync create-task \
    --source-location-arn “arn:aws:datasync:us-west-2:accountId:location/loc-xxxxxxxxxxxxxx” \
    --destination-location-arn “arn:aws:datasync:us-west-2:accountId:location/loc-xxxxxxxxxxxxxx”

Enter fullscreen mode Exit fullscreen mode

extra-large Architecture diagram

YouTube Tutorial

References

  1. https://docs.aws.amazon.com/datasync/latest/userguide/what-is-datasync.html.
  2. https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html.
  3. https://docs.aws.amazon.com/systems-manager/latest/userguide/fleet-manager-default-host-management-configuration.html.
  4. https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html.
  5. https://docs.aws.amazon.com/datasync/latest/userguide/datasync-network.html.