# Migrating Data using AWS Storage Gateway in File Gateway mode and Enabling Cross Region Replication between Buckets.

## Introduction:

Data migration and disaster recovery are key considerations for building resilient cloud architectures. A common requirement is to migrate data from an **local machine** to a **primary Amazon S3 bucket**, while ensuring that the same objects are **automatically replicated to a secondary bucket** in **another AWS region**. This setup not only simplifies data migration but also provides high availability, durability, and cross-region redundancy without manual intervention.

## Architecture Diagram:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739255026247/10db04a1-de6f-42d5-abd3-5b5f4e619f99.png align="left")

## Procedures:

**Step1:** Login to your **AWS Management Console** and change the region to **us-east-2.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739248423229/83874ad5-e2f3-4b14-a8d1-c566775818ad.png align="left")

**Step2:** Create **two S3 Bucket** in **different regions** and **enable versioning** for **cross region replication.**

* We name the **Primary** Bucket “**abisbucket**” in AWS region **“us-east-2”**
    
* **Secondary** Bucket be **“abisbucket101”** in AWS region **“us-west-2”**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739248248233/28ebd246-3e00-477f-93e3-c4763580ca8d.png align="center")

* Bucket versioning **Enable.**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739248277609/7fc75675-b2ea-47be-8a93-daf624f4071a.png align="center")

* Similary, Create another bucket.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739248372274/0b7fa2c4-a059-42e9-a0b5-e721f3cb048c.png align="center")

**Step3:** Creating **Replication Rule** to the Primary Bucket.

* Select the primary bucket named, here “**abisbucket**“
    
* Navigate to the **Management tab**
    
* Navigate to **Replication rules** and
    
* Click **create replication rule.**
    
* Enter the **Name** for Replication rule. eg: “**crr-full-bucket**“
    
* keep the **Status Enabled**.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739248582259/f859a93d-a8cb-4526-9cf9-18cb60a7a984.png align="center")

* Under the **Source bucket**, **Apply to all objects in the bucket**
    
* From **Destination** Section, **Choose the bucket in this account**
    
* **Browse S3 Bucket** that you have created as **Secondary.**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739248611566/d970f2ac-a34d-42ed-b98f-35f05ebdfa8e.png align="center")

* Under **IAM role**, Select **Create new role** or if you have already created an Role **Choose existing IAM roles.**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739248671565/60b9ce62-95bb-4009-87e4-1a3721e8b06a.png align="center")

* For now we have just created an bucket and doesn’t contains any objects so choose **Not to replicate existing objects.**
    
* Click on **Submit.**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739248782253/f1d2d2d1-db27-4e1d-88b6-79422a4aee32.png align="left")

**Step4:** Checking whether **CRR** is Successful or Not.

* Upload an file to the Primary Bucket “**abisbucket**“
    
* Navigate to the Seconday Bucket “**abisbucket101**“, You should be able to see the objects uploaded in the primary bucket.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739248919657/267d3671-13b3-4ef9-99f8-b0ab71849ef0.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739249002418/8e5900c4-4aea-4ee3-9910-c09489d2a5c8.png align="center")

**Step5:** Setting up **Storage Gateway**

* In your Management console type **Storage Gateway** on the search box and **click it** to open.
    
* Click on **create gateway**
    
* Enter the Gateway name , For now “**File Gateway**“
    
* Under Gateway options, Choose **Amazon S3 File Gateway**.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739249181765/6d8eb10a-f0b8-4887-a155-7d5c284730d8.png align="left")

* Select **Amazon EC2** from Platform options.
    
* Choose **Customize your settings** from the Launch EC2 instance.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739249294790/4a62a9c0-2ac1-4f36-b46e-d00fe1eeee96.png align="center")

* Click on **Launch instance** under Set up gateway on Amazon EC2
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1744090161967/09f04e46-4b54-4be9-b7ea-5902fe321ab7.png align="left")

**Step6:** Fill out the details to **create an instance.**

![](https://miro.medium.com/v2/resize:fit:1250/1*EPq-FGkRWnGY3yLVIQ6xSg.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1744090685154/50613b14-874b-408d-b70d-24ddc95e2f21.png align="left")

* Enter the name of the instance (you can choose any name),
    
* for the AMI it is automatically selected for you,
    
* on the instance type select **t2.micro,**
    
* on the key pair you can proceed with vockey or just proceed to create your own,
    
* on the network settings I would prefer you use a VPC that you have already created and make sure to enable elastic IP address,
    
* choose the security group associated with the instance,
    
* if the volume is not enough go ahead and add a new volume so that your data will be able to fit without any disruptions,
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739249815614/ee16cb7e-6e4f-445b-ac94-af95968fe060.png align="left")

* after doing all of this go ahead and review all the settings and if everything is looking good
    
* launch the instance.
    
* You will receive a sucess message that your instance has been created successfully.
    
* Your instance is going to take a few minutes to initialize. Monitor the deployment until the status check to complete.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739249904628/daa6b046-f337-4f72-93a5-3dba89305e55.png align="center")

* Copy the above instance **Public IP address.**
    
* On the Gateway Tab on **Step2** , Select IP address connection options and **Paste** the copied instance public ip address.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739249959869/91b9a3ba-2320-469d-9c3f-39a3f34f7336.png align="center")

* Choose **Publicly accessible** in the Endpoint options.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739250034755/b9145b6b-072b-4d91-a90b-b584417f4f41.png align="center")

* After all of this choose next and review and activate settings and choose activate gateway. You will receive a success message as the on below and make sure the status is running.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739250160389/73d0eb37-7773-4894-b4af-574eb5e03072.png align="center")

**Step7: Create file Share**

* After successfully creating the File Gateway and the status is displaying running the proceed and **create file share at the top right hand side.** You will happen to see the page below.
    

![](https://miro.medium.com/v2/resize:fit:1250/1*W0287QD0aGuhmeyJkG1EsA.png align="left")

* Select the Name of the Gateway you just created
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739250647099/dfea988b-55c9-45ee-bbb3-41f412b092f4.png align="center")

* On the S3 bucket choose the **primary bucket** that you had already created, then choose customize configuration or you can go right ahead to create file share.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739250856572/c8480aca-e338-42b5-a50a-a51abe2e96ab.png align="center")

* For the file share protocol, I will use **NFS** since am using Linux and my instance is also Linux,
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739251026823/0bebd903-edc6-4e58-8031-8272bf111d8b.png align="center")

* You can see the File share has been created successfully and added to the gateway.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739251130945/7a15cba7-5f14-44c5-8751-e34502d70760.png align="center")

you have successfully created a storage gateway and you are almost there, it should be running just fine.

**Now,**

We need to mount the file share to Linux instance for migrating the data.

**Step8: Connect to on premises instance and migrate the data to S3.**

* Create the directory that will be used to synchronize data with your S3 bucket.
    

```bash
ssh -i </path/to/key-file> ec2-user@<ip-addess>
sudo mkdir -p /mnt/nfs/s3
```

* Then mount the file share on the Linux instance by using the command that you located in the Storage Gateway file shares details screen at the end of the last task.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739251142787/12d784a6-76a2-49ae-9c5f-4426b0be834d.png align="center")

```bash
sudo mount -t nfs -o nolock,hard 10.10.1.98:/abisbucket [MountPath]
#example:
sudo mount -t nfs -o nolock,hard 10.10.1.98:/abisbucket /mnt/nfs/s3*
#view if the bucket is mounted to your instance mountpoint
df-h
#copy the data to the mountpoint
cp -v <file/Path> </mountpoint>
#example
cp -v /media/data/* /mnt/nfs/s3
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739251734207/edd11442-d8c2-4f5d-8733-33171207bb6d.png align="center")

**Step9:** **Confirming Migrations**

Check whether the data have been migrated to the primary S3 bucket and also to the secondary bucket form the primary bucket.

* To verify that your data has been migrated you can go back to the management console and search for S3.
    
* Select the Primary Bucket “**abisbucket“**
    
* you can see the files migrated to the bucket form the instance.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739251821985/b1c90b7c-5a02-4fc2-be14-d2a5bac30ffc.png align="center")

* Now, select the Seconday Bucket “**abisbucket101**“
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739251879207/605f24d0-73a2-4a29-9942-c0449dfd699a.png align="center")

* you can see all the objects have been replicated from the Primary Bucket.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739251907637/8a1e8021-2684-4950-bbd4-82500a65eef0.png align="center")

## **Conclusion:**

we have successfully migrated data to Amazon S3 by using AWS Storage Gateway in File Gateway mode. Being a hybrid storage solution AWS Storage Gateway is a highly adaptable solution. It can serve a broad range of use cases, from primary backups and disaster recovery to comprehensive data migrations or cloud resources for various workloads.
