<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nayan Arora on Medium]]></title>
        <description><![CDATA[Stories by Nayan Arora on Medium]]></description>
        <link>https://medium.com/@nayanarora55?source=rss-811b4ede7020------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Z_I5GFCQ6hAJoLLREnMWhA.jpeg</url>
            <title>Stories by Nayan Arora on Medium</title>
            <link>https://medium.com/@nayanarora55?source=rss-811b4ede7020------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 14:30:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nayanarora55/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Cross-Account S3 Migration: AWS DataSync Does It So You Don’t Have To…]]></title>
            <link>https://medium.com/@nayanarora55/cross-account-s3-migration-aws-datasync-does-it-so-you-dont-have-to-9b85a23d1464?source=rss-811b4ede7020------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b85a23d1464</guid>
            <category><![CDATA[aws-datasync]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Nayan Arora]]></dc:creator>
            <pubDate>Fri, 19 Jan 2024 19:00:10 GMT</pubDate>
            <atom:updated>2024-01-19T19:00:10.286Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sFuzuWaGxEdm2vzbv4XEvA.png" /></figure><p>Data is a blessing, but when it comes to migrating it from one place to another, it can feel like a curse. This is especially true in cases like moving your Master Database from one AWS account to another, or migrating your S3 bucket to a different account.</p><p>However, there is a solution to make this challenging migration process as smooth as butter. For S3 migration, you can use the <a href="https://aws.amazon.com/datasync/"><strong>AWS DataSync Service</strong></a>, and for database migrations, the <a href="https://aws.amazon.com/dms/"><strong>AWS Database Migration</strong></a> Service is available. In this blog, we will focus in-depth on how to use the DataSync service to accomplish our task.</p><h3>Prerequisites</h3><p>To get started, ensure you have access to both AWS accounts. Let’s be clear about the terms from the beginning. “<strong>Source account ” </strong>means the account from where we want to transfer the data and the “<strong>Destination account” </strong>is the one where the data will be transferred into a new bucket.</p><blockquote><em>Before we dive into creating the data migration task. Make sure to setup </em><strong><em>aws-cli</em></strong><em> on your local system or your server. If not done yet, check the steps below first.</em></blockquote><pre>Run command on your terminal - aws sts get-caller-identity<br>if you get output like this, then you are all set. <br>  {<br>      &quot;UserId&quot;: &quot;A*****************Y&quot;,<br>      &quot;Account&quot;: &quot;your_account_id&quot;,<br>      &quot;Arn&quot;: &quot;arn:aws:iam::your_account_id:user/awsUser&quot;<br>  }<br><br>If you get an error or something else then follow this.<br><a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html#getting-started-install-instructions"><strong>https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html#getting-started-install-instructions</strong></a><br></pre><h3>Let’s Begin…</h3><h4><strong>Step 1 — </strong>Configure an <strong>IAM </strong>role in the source Account</h4><p>The reason behind this is, we will need to access the both buckets for the migration task. According to <strong>AWS </strong>Documentation for DataSync service<strong> two IAM roles</strong> are required but with the procedure defined in this blog, only <strong>one IAM role </strong>will be enough.</p><p><strong>a)</strong> Go to IAM Dashboard and click on users.</p><p><strong>b)</strong> Click create role and you shall see the following screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9n5Bo4gzAm38NYRM2tRJw.png" /><figcaption>Create role screen</figcaption></figure><p><strong>c)</strong> Select “<strong>Trusted entity type” </strong>as AWS service and “<strong>DataSync</strong>” as the service.</p><p><strong>d)</strong> Click next and <strong>create role</strong> with name of your choice, for this blog we will call this role as “<strong>data-sync-role</strong>”.</p><p><strong>e)</strong> After creating the role, open that role and click on <strong>Add permissions — &gt; Create inline policy </strong>and add the below json and save.</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Action&quot;: [<br>                &quot;s3:GetBucketLocation&quot;,<br>                &quot;s3:ListBucket&quot;,<br>                &quot;s3:ListBucketMultipartUploads&quot;<br>            ],<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Resource&quot;: &quot;<strong>arn:aws:s3:::sourceBucket</strong>&quot;<br>        },<br>        {<br>            &quot;Action&quot;: [<br>                &quot;s3:AbortMultipartUpload&quot;,<br>                &quot;s3:DeleteObject&quot;,<br>                &quot;s3:GetObject&quot;,<br>                &quot;s3:ListBucket&quot;,<br>                &quot;s3:ListMultipartUploadParts&quot;,<br>                &quot;s3:PutObject&quot;,<br>                &quot;s3:GetObjectTagging&quot;,<br>                &quot;s3:PutObjectTagging&quot;<br>            ],<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Resource&quot;: &quot;<strong>arn:aws:s3:::sourceBucket/*</strong>&quot;<br>        },<br>        {<br>            &quot;Action&quot;: [<br>                &quot;s3:GetBucketLocation&quot;,<br>                &quot;s3:ListBucket&quot;,<br>                &quot;s3:ListBucketMultipartUploads&quot;<br>            ],<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Resource&quot;: &quot;<strong>arn:aws:s3:::destinationBucket</strong>&quot;<br>        },<br>        {<br>            &quot;Action&quot;: [<br>                &quot;s3:AbortMultipartUpload&quot;,<br>                &quot;s3:DeleteObject&quot;,<br>                &quot;s3:GetObject&quot;,<br>                &quot;s3:ListBucket&quot;,<br>                &quot;s3:ListMultipartUploadParts&quot;,<br>                &quot;s3:PutObject&quot;,<br>                &quot;s3:GetObjectTagging&quot;,<br>                &quot;s3:PutObjectTagging&quot;<br>            ],<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Resource&quot;: &quot;<strong>arn:aws:s3:::destinationBucket/*</strong>&quot;<br>        }<br>    ]<br>}<br><br>Note - Replace the <strong>ARN </strong>of source and destination bucket with your <strong>ARN&#39;s</strong></pre><p><strong>f)</strong> Now in the “<strong>data-sync-role</strong>” page click on <strong>Trust Relationships </strong>and edit the json to look like below</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;Service&quot;: &quot;datasync.amazonaws.com&quot;<br>            },<br>            &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>        }<br>    ]<br>}</pre><h4>Step 2 — Update the Bucket policies in source and destination account</h4><p>We need to update the S3 bucket policies for the both <strong>sourceBucket</strong> and <strong>destinationBucket </strong>firstly to make sure that the <strong>data-sync-role </strong>is able to access both and secondly the both buckets can communicate with each other.</p><p><strong>a)</strong> Open <strong>sourceBucket </strong>in console and go to the <strong>Permissions tab</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0RK89eIS2BcGlc0dFdJWHw.jpeg" /><figcaption>Bucket Detail page</figcaption></figure><p><strong>b) </strong>Click Edit in <strong>Bucket Policy </strong>and add the following policy and <strong>save</strong>.</p><pre>{<br>  &quot;Version&quot;: &quot;2008-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;DataSyncCreateS3LocationAndTaskAccess&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Principal&quot;: {<br>        &quot;AWS&quot;: &quot;arn:aws:iam::your_account_id:role/data-sync-role&quot;<br>      },<br>      &quot;Action&quot;: [<br>        &quot;s3:GetBucketLocation&quot;,<br>        &quot;s3:ListBucket&quot;,<br>        &quot;s3:ListBucketMultipartUploads&quot;,<br>        &quot;s3:AbortMultipartUpload&quot;,<br>        &quot;s3:DeleteObject&quot;,<br>        &quot;s3:GetObject&quot;,<br>        &quot;s3:ListMultipartUploadParts&quot;,<br>        &quot;s3:PutObject&quot;,<br>        &quot;s3:GetObjectTagging&quot;,<br>        &quot;s3:PutObjectTagging&quot;<br>      ],<br>      &quot;Resource&quot;: [<br>        &quot;arn:aws:s3:::fitmint&quot;,<br>        &quot;arn:aws:s3:::fitmint/*&quot;<br>      ]<br>    }<br>  ]<br>}<br><br>Note - Replace &quot;<strong>your_account_id</strong>&quot; with your AWS Account ID.</pre><p><strong>c) </strong>Now we need to update the <strong>Object Ownership </strong>to look like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFxC9tXS_8k860KFcEJyoQ.png" /><figcaption>You can find this option after the <strong>Bucket Policy </strong>section</figcaption></figure><p><strong>d) </strong>Now click on <strong>edit</strong> in <strong>Access control list (ACL) </strong>and add the <strong>Canonical ID </strong>of <strong>destinationBucket </strong>here .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*Ca5ojf7qKs5jPd6OE43E2w.png" /><figcaption>You can find the <strong>Canonical ID destinationBucket</strong> in <strong>ACL</strong> section in <strong>Permissions</strong> tab of <strong>destinationBucket</strong>.</figcaption></figure><p><strong>e) </strong>Now we need to configure the <strong>destinationBucket, </strong>firstly we need to update the following <strong>bucket policy </strong>in the destination.</p><pre>{<br>    &quot;Version&quot;: &quot;2008-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;DataSyncCreateS3LocationAndTaskAccess&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;AWS&quot;: &quot;arn:aws:iam::source-account-id:role/data-sync-role&quot;<br>            },<br>            &quot;Action&quot;: [<br>                &quot;s3:GetBucketLocation&quot;,<br>                &quot;s3:ListBucket&quot;,<br>                &quot;s3:ListBucketMultipartUploads&quot;,<br>                &quot;s3:AbortMultipartUpload&quot;,<br>                &quot;s3:DeleteObject&quot;,<br>                &quot;s3:GetObject&quot;,<br>                &quot;s3:ListMultipartUploadParts&quot;,<br>                &quot;s3:PutObject&quot;,<br>                &quot;s3:GetObjectTagging&quot;,<br>                &quot;s3:PutObjectTagging&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;arn:aws:s3:::destinationBucket&quot;,<br>                &quot;arn:aws:s3:::destinationBucket/*&quot;<br>            ]<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;DataSyncCreateS3Location&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;AWS&quot;: &quot;arn:aws:iam::source-account-id:role/data-sync-role&quot;<br>            },<br>            &quot;Action&quot;: &quot;s3:ListBucket&quot;,<br>            &quot;Resource&quot;: &quot;arn:aws:s3:::destinationBucket&quot;<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;UserDataSyncCreateS3Location&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;AWS&quot;: &quot;arn:aws:iam::source-account-id:user/awsUser&quot;<br>            },<br>            &quot;Action&quot;: &quot;s3:ListBucket&quot;,<br>            &quot;Resource&quot;: &quot;arn:aws:s3:::destinationBucket&quot;<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;AllowPublicRead&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;AWS&quot;: &quot;*&quot;<br>            },<br>            &quot;Action&quot;: &quot;s3:GetObject&quot;,<br>            &quot;Resource&quot;: &quot;arn:aws:s3:::destinationBucket/*&quot;<br>        }<br>    ]<br>}<br><br><br>Note :- <br>&quot;<strong>source-account-id</strong>&quot; - replace it with the <strong>source</strong> AWS Account ID<br>&quot;<strong>awsUser</strong>&quot; - This is IAM user of source account we configured with <strong>AWS-CLI</strong>.</pre><p><strong>f) </strong>Now we need to update the <strong>Object Ownership </strong>for the <strong>destinationBucket</strong> as done in point <strong>“c”</strong> above.</p><p><strong>g) </strong>Now click on <strong>edit</strong> in <strong>Access control list (ACL) </strong>and add the <strong>Canonical ID </strong>of <strong>sourceBucket </strong>here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*Ca5ojf7qKs5jPd6OE43E2w.png" /><figcaption>You can find the <strong>Canonical ID destinationBucket</strong> in <strong>ACL</strong> section in <strong>Permissions</strong> tab of <strong>destinationBucket</strong>.</figcaption></figure><h4>Step 3— Create a new DataSync Task</h4><p><strong>Kudos</strong>, you have successfully configured both the buckets. Now we can move onto create a <strong>Task </strong>to move our data from one bucket to another.</p><p>First we need to create the <strong>datasync-location </strong>for our source S3 bucket, to do so run the following command in the terminal we setup the <strong>aws-cli </strong>.</p><pre>aws datasync create-location-s3 \<br>  --s3-bucket-arn arn:aws:s3:::destinationBucket \<br>  --s3-config &#39;{<br>    &quot;BucketAccessRoleArn&quot;:&quot;arn:aws:iam::your-account-id:role/data-sync-role&quot;<br>  }&#39;</pre><p>If the output of above comes something like this, then its all good.</p><pre>{<br>    &quot;LocationArn&quot;: &quot;arn:aws:datasync:ap-southeast-1:561031111111:location/loc-09536afabbbbbbb&quot;<br>}</pre><p>If you receive , error like below then cross-check the steps with <strong>IAM role has all permissions required, bucket-policy</strong>, <strong>ACL</strong>, <strong>Canonical ID</strong> and that shall resolve the issue</p><pre>DataSync bucket access test failed: could not perform s3:HeadBucket on bucket fitmint-test-bucket. Access denied. Ensure bucket access role has s3:ListBucket permission.</pre><p>After we have create the location using create-location cmd, now we can move onto the DataSync dashboard and create our first <strong>Task.</strong></p><p>Go to DataSync dashboard and click on <strong>Create task </strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fvdtXhmVD1P2derLu3WzTA.png" /><figcaption>Screen 1</figcaption></figure><p>Select <strong>Location type </strong>as “<strong>Amazon S3” , </strong>region your sourceBucket is in and the sourceBucket , select the <strong>IAM role “data-sync-role” </strong>and then click on Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JAv4DO2VKt7efW7l2I2FMA.png" /><figcaption>Screen 2</figcaption></figure><p>Now click on choose existing location and you will be able to see your <strong>destinationBucket </strong>name in the dropdown if the selected region is correct.</p><p>Click next and give a name of your choice and schedule to task and submit it.</p><p>If you have defined a schedule then the task will automatically start, incase not then you need to <strong>start </strong>the task manually as in below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hiyhLv0Dvo_eoSrXFQZ72w.jpeg" /><figcaption>Task list</figcaption></figure><p>And then you can see its progress in <strong>task-history </strong>or check the <strong>cloud-tail logs.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wKsDBxkw5PKMTYh4Z3Z6fw.png" /><figcaption>Task History Screen</figcaption></figure><p><strong>Time to “Pat yourself on the back”, </strong>you have done a great job !</p><p>Hope you find this helpful. In the next blog let’s discuss how we can migrate our production database without losing any data from one AWS account to another.</p><p>Let’s connect —<strong> </strong><a href="https://www.linkedin.com/in/aroranayan/"><strong>https://www.linkedin.com/in/aroranayan/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b85a23d1464" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>