How to configure replication in AWS EFS?
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
You can create a copy of your EFS file system to another region by setting up replication in your EFS file system.
What is replication in AWS EFS?
You can use Amazon EFS replication to create a replica of your Amazon EFS file system in the AWS Region of your preference. When you enable replication on an EFS file system, Amazon EFS automatically and transparently replicates the data and metadata on the source file system to a new destination EFS file system. To manage the process of creating the destination file system and keeping it synced with the source file system, Amazon EFS uses a replication configuration.
Amazon EFS automatically keeps the source and destination file systems synchronized. Amazon EFS replication is continual and designed to provide a recovery point objective (RPO) and a recovery time objective (RTO) of minutes.
Amazon EFS creates the destination file system with read-only permissions. After the destination file system is created, Amazon EFS performs the initial sync that copies all data and metadata on the source to the destination file system. The amount of time that the initial sync takes to finish depends on the size of the source file system. After the initial sync is finished, the replication process continually keeps the destination file system in sync with the source.
To failover to the destination file system in a replication configuration, you must delete the replication configuration. After the replication configuration is deleted, the destination file system becomes writeable, and you can start using it in your application workflow. This process can take several minutes to complete.
Note: Because a destination file system is read-only while it is a member of a replication configuration, Amazon EFS does not create any mount targets when it creates the destination file system, and any write operations to the destination file system will fail till its part of the replication configuration.
How to configure replication in AWS EFS?
Prerequisites:
AWS CLI installed and configured.
Step 1: Create a new EFS file share that will serve as the source of our EFS replication configuration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
## Create a source EFS fileshare aws efs create-file-system \ --performance-mode generalPurpose \ --throughput-mode bursting \ --no-encrypted \ --no-backup \ --availability-zone-name ap-south-1a \ --tags Key=Name,Value=myfilesystem ## Get default VPC, SG, Subnet and EFS Filesystem ID DEFAULT_VPC_ID=$(aws ec2 describe-vpcs \ --query 'Vpcs[?IsDefault == `true`].VpcId' \ --output text) && echo $DEFAULT_VPC_ID SUBNET_ID=$(aws ec2 describe-subnets \ --filters "Name=vpc-id,Values=$DEFAULT_VPC_ID" \ --query 'Subnets[?AvailabilityZone == `ap-south-1a`].SubnetId' \ --output text) && echo $SUBNET_ID DEFAULT_SECURITY_GROUP_ID=$(aws ec2 describe-security-groups \ --filters "Name=vpc-id,Values=$DEFAULT_VPC_ID" \ --query 'SecurityGroups[?GroupName == `default`].GroupId' \ --output text) && echo $DEFAULT_SECURITY_GROUP_ID FILE_SYSTEM_ID=$(aws efs describe-file-systems \ --query 'FileSystems[0].FileSystemId' \ --output text) && echo $FILE_SYSTEM_ID ## Create a mount target for your source EFS aws efs create-mount-target \ --file-system-id $FILE_SYSTEM_ID \ --subnet-id $SUBNET_ID \ --security-groups $DEFAULT_SECURITY_GROUP_ID |
Step 2: Create EFS replication configuration using AWS CLI
1 2 3 4 |
## Create EFS replication configuration aws efs create-replication-configuration \ --source-file-system-id $FILE_SYSTEM_ID \ --destinations 'Region=ap-south-1,AvailabilityZoneName=ap-south-1b' |
Note: For demo purposes, I have given the same region for the target EFS file system as the source EFS file system but you can give any supported region within the same AWS account. For EFS of type “one zone”, you need to provide the availability zone as well in the “destination” parameter.
Step 3: Get details on your EFS replication configuration using AWS CLI.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
## Get details on the EFS replication configuration aws efs describe-replication-configurations \ --file-system-id $FILE_SYSTEM_ID ## returns ## { ## "Replications": [ ## { ## "SourceFileSystemId": " ## "SourceFileSystemRegion": "ap-south-1", ## "SourceFileSystemArn": "arn:aws:elasticfilesystem:ap-south-1: ## "OriginalSourceFileSystemArn": "arn:aws:elasticfilesystem:ap-south-1: ## "CreationTime": "2022-03-22T11:40:28+05:30", ## "Destinations": [ ## { ## "Status": "ENABLED", ## "FileSystemId": " ## "Region": "ap-south-1", ## "LastReplicatedTimestamp": "2022-03-22T11:40:14.965000+05:30" ## } ## ] ## } ## ] ## } |
We have successfully configured replication in AWS EFS.
Step 4: Clean up.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
## Delete replication configuration aws efs delete-replication-configuration \ --source-file-system-id $FILE_SYSTEM_ID ## Delete the efs mount target MOUNT_TARGET_ID=$(aws efs describe-mount-targets \ --file-system-id $FILE_SYSTEM_ID | jq -r .MountTargets[0].MountTargetId) && aws efs delete-mount-target \ --mount-target-id $MOUNT_TARGET_ID ## Delete the source efs aws efs delete-file-system \ --file-system-id $FILE_SYSTEM_ID ## Delete the target efs aws efs delete-file-system \ --file-system-id |
Hope you have enjoyed this article. To get more details in AWS EFS, please refer the below documentation
https://docs.aws.amazon.com/efs/index.html