# Amazon S3 Bucket Migration between AWS Account

### Overview

Imagine you have 5000 audio files in your Amazon S3 bucket and you want to move it to a new AWS Account. But there is one caveat you cannot zip the audio folder download it to your local machine and upload it to the new AWS Account.

So what you would do? Don’t worry you are in the right place for the solution

In this post, you will learn how to migrate the data/objects of S3 Bucket from one AWS account to another AWS account

### Objectives

1. What is Amazon S3
    
2. Getting the Destination AWS Account Number
    
3. Attaching the policy in Source S3 Bucket
    
4. Attaching the policy in Destination AWS Account IAM User
    
5. Installing the AWS CLI in the Local Machine
    
6. Configuring the Access Key ID and Secret ID
    
7. Syncing S3 objects to Destination AWS Account
    

### Prerequisites

* AWS Account (If you don’t have an account [click here to create an account](https://portal.aws.amazon.com/billing/signup?sc_icampaign=consolesignout_generic_createaccount_cta&sc_ichannel=ha&sc_icontent=awssm-1111&sc_iplace=cta&trk=ha_awssm-1111&redirect_url=https%3A%2F%2Faws.amazon.com%2Fregistration-confirmation#/start))
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056327289/f7bb9a56-3173-42eb-a670-5b19aee194dd.png align="left")

### 1\. What is Amazon S3

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. It can be used by all sizes of industries which can store and protect data for a range of use cases such as websites, mobile apps, backup, and restore enterprise applications.

### 2\. Getting the Destination AWS Account Number

* Sign in to the AWS Management Console account for the destination account
    
* Once signed in the navigation bar click **support** and then click **Support center**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056329089/e5b74464-c380-436d-81d3-fecdd0621c5e.jpeg align="left")

Once the **Support center** is clicked you can see a screen like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056330697/ed3309d9-8bca-41fe-a893-79775058ef0e.jpeg align="left")

On the left-hand side, you can see the **Account number** for your destination AWS Account Copy that number.

### 3\. Attaching the policy in Source S3 Bucket

Now go to your source AWS account and then select S3 Bucket

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056333187/757e8a2e-41eb-4ec2-80c7-405f1001bd21.jpeg align="left")

Select the Bucket which you want to migrate

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056334701/4a5fb508-94fe-44cb-8f50-36ca4b03e4c2.jpeg align="left")

Click on the **permission** tab and select **Bucket policy** like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056336416/574f451e-c53b-49bd-b998-c8554b5df394.jpeg align="left")

In the policy editor add the below configuration

If your bucket has **public access** then do like below

### 4\. Attaching the policy in Destination AWS Account IAM User

Goto your **Destination AWS account** and select **IAM** user like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056338157/932dcf33-da2e-413e-9b35-68ed3634cf08.jpeg align="left")

Click on the IAM option which will navigate to the screen like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056339670/8ac69256-3a4d-42f9-b61f-333b2e3a142f.jpeg align="left")

Click on the Policies on the left-hand side which would open a screen like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056341997/3afb85fa-d75e-473f-b951-e323ccf5f406.jpeg align="left")

Click on the Create policy and then click on the **JSON** tab

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056343723/1d5e79bf-de74-47b3-975e-457bc2fc754d.jpeg align="left")

Now replace the policy with the below code

Once the policy is added click on the **Review policy** like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056345438/6a2a820f-fc50-4b4d-816d-6e6f6c18980f.jpeg align="left")

Which will open a new page where you can fill in the **policy name** like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056346854/24b98edf-bf93-4037-9d2e-3928af6490d1.jpeg align="left")

Now click on the **Create Policy button**. Once the policy is created click on the User on the left-hand side like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056348277/a662c433-d487-4c01-aa1c-2525fb7c2589.jpeg align="left")

Now click **Add User** and then you can see a screen like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056349762/52ff1cb8-3881-4188-bfbf-43f9890a1803.jpeg align="left")

Fill in the user name select the Access type as **Programmatic access** and then click **Next Permissions**

Now you can see a page like below and select **Attach existing policies** directly

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056351292/ed2617bf-3dd1-43c9-9419-56704717e4a0.jpeg align="left")

Attach existing policies directly

In the Filter, policies type the policy name which we created earlier below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056352660/43d00f34-5b84-4f12-a267-a9b018e1934b.jpeg align="left")

Click **Next Tags** and then in the last section you can see the credentials below

> *Download the credentials to your local machine because it will be shown only once*

### 5\. Installing the AWS CLI in the Local Machine

Now we will install the **AWS CLI** in the Local Machine for that open your terminal and type the below command (Mac and Linux Machine)

```bash
sudo pip install awscli
```

Once it is installed check whether AWS CLI is installed properly with the command

```bash
aws help
```

Now you could see an output like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056354287/5ad340ca-46b5-4793-ab34-3b0ac1991eef.png align="left")

### 6\. Configuring the Access Key ID and Secret ID

Now we will configure the **AWS Destination account Access key and Secret key** in the AWS CLI

Open the terminal and give the command

```bash
aws configure
```

which would ask for the **Access key** and **secret ID** like below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698056356181/7fa21887-9357-4556-8e96-6579883fa6b4.jpeg align="left")

Configuring Access Key ID and Access Key

Add the Access Key ID, Secret Access Key and enter the default region of your Destination AWS account and then type table to show the output in table format else press Enter which will use the Default JSON option

Once the configuration is done it’s time for migration

### 7\. Syncing S3 objects to Destination AWS Account

To Sync the S3 objects from Source to Destination AWS account use the below command in your terminal

```bash
aws s3 sync s3://YOUR-SOURCE-BUCKET-NAME-HERE s3://YOUR-DESTINATION-BUCKET-NAME-HERE --source-region SOURCE-REGION-NAME --region DESTINATION-REGION-NAME
```

Replace the source bucket name, destination bucket name, and source, and destination region like below

```bash
aws s3 sync s3://my-us-west-2-bucket s3://my-ap-south-1-bucket --source-region us-west-2 --region ap-south-1
```

Now click enter which will start copying the files from your Source Bucket to Destination Bucket :)

### I have some doubts

#### Question #1

**Q**: I have multiple folders in my **Source S3 Bucket** and i want to copy only one folder to the **Destination S3 Bucket** for that what shall i do

**A**: It is very simple just change the command like below and click Enter which will copy only one folder

aws s3 sync s3://my-us-west-2-bucket/folder1 s3://my-ap-south-1-bucket/folder1 --source-region us-west-2 --region ap-south-1

#### Question #2

**Q**: I have added new audio in my **Source S3 Bucket** and i want to copy that one to the **Destination S3 Bucket**. If i give the above command will it copy all the **5001 audio files** or just the **1 audio file**

**A**: It will copy/sync only the **1 audio file** and not the other audio files from your **Source S3 Bucket**

#### Question #3

**Q**: I have **renamed** a file in **Source S3 Bucket** and now i am giving the above command will it replace the **existing file** in the **Destination S3 Bucket**?

**A**: **No** it will create as a **new file** in **Destination S3 Bucket** keeping the old one as it is.

### Congratulations!

You have learned how to Copy/Sync files from one AWS Account to another AWS Account. **Happy Learning!!!!**
