{"id":1599,"date":"2019-05-05T02:09:44","date_gmt":"2019-05-04T20:09:44","guid":{"rendered":"http:\/\/techsatwork.com\/blog\/?p=1599"},"modified":"2019-05-05T07:56:36","modified_gmt":"2019-05-05T01:56:36","slug":"copy-s3-objects-across-aws-accounts","status":"publish","type":"post","link":"https:\/\/techsatwork.com\/?p=1599","title":{"rendered":"Copy S3 objects across AWS Accounts"},"content":{"rendered":"\n<p>This will show you how to copy objects  between S3 buckets across different AWS Accounts.  Its not an easy drag and drop. Not sure why Amazon doesn&#8217;t provide an easy &#8220;SFTP&#8221; like feature.  Here are the steps:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Prerequisites<br><\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>You would need access to both the AWS accounts<\/li><li>You need IAM user access on the destination<\/li><li>AWS account number of the destination.<\/li><li>You need to have the AWS CLI configured on your machine with the IAM user that you created\/used from earlier step.<\/li><\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Get AWS Account number<\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>Login to the destination AWS account<\/li><li>Go to My Account page and copy the Account ID<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/techsatwork.com\/blog\/wp-content\/uploads\/2019\/05\/image.png\" alt=\"\" class=\"wp-image-1603\" width=\"416\" height=\"115\" srcset=\"https:\/\/techsatwork.com\/wp-content\/uploads\/2019\/05\/image.png 717w, https:\/\/techsatwork.com\/wp-content\/uploads\/2019\/05\/image-300x83.png 300w\" sizes=\"auto, (max-width: 416px) 100vw, 416px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Set S3 policy on source account<\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>Login to the source AWS account<\/li><li>Go to the S3 bucket<\/li><li>Create the following policy to the bucket<\/li><\/ol>\n\n\n\n<p class=\"has-text-color has-small-font-size has-luminous-vivid-orange-color\">{<br>     &#8220;Version&#8221;: &#8220;2012-10-17&#8221;,<br>     &#8220;Statement&#8221;: [<br>         {<br>             &#8220;Sid&#8221;: &#8220;DelegateS3Access&#8221;,<br>             &#8220;Effect&#8221;: &#8220;Allow&#8221;,<br>             &#8220;Principal&#8221;: {<br>                 &#8220;AWS&#8221;: &#8220;arn:aws:iam::<strong>DESTINATION_BUCKET_ACCOUNT_NUMBER<\/strong>:root&#8221;<br>             },<br>             &#8220;Action&#8221;: [<br>                 &#8220;s3:ListBucket&#8221;,<br>                 &#8220;s3:GetObject&#8221;<br>             ],<br>             &#8220;Resource&#8221;: [<br>                 &#8220;arn:aws:s3:::<strong>SOURCE_BUCKET_NAME<\/strong>\/*&#8221;,<br>                 &#8220;arn:aws:s3:::<strong>SOURCE_BUCKET_NAME<\/strong>&#8220;<br>             ]<br>         }<br>     ]<br> }<\/p>\n\n\n\n<p>Replace <strong>DESTINATION_BUCKET_ACCOUNT_NUMBER<\/strong> with the account ID that you copied earlier. Replace the <strong>SOURCE_BUCKET_NAME<\/strong> with the actual bucket name.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Attach policy on the destination account<\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>Login to the destination AWS account<\/li><li>Go to my security credentials<\/li><li>Select policies <\/li><li>Add the following as the new policy for the IAM user<\/li><\/ol>\n\n\n\n<p class=\"has-text-color has-small-font-size has-luminous-vivid-orange-color\">{<br>     &#8220;Version&#8221;: &#8220;2012-10-17&#8221;,<br>     &#8220;Statement&#8221;: [<br>         {<br>             &#8220;Effect&#8221;: &#8220;Allow&#8221;,<br>             &#8220;Action&#8221;: [<br>                 &#8220;s3:ListBucket&#8221;,<br>                 &#8220;s3:GetObject&#8221;<br>             ],<br>             &#8220;Resource&#8221;: [<br>                 &#8220;arn:aws:s3:::<strong>SOURCE_BUCKET_NAME<\/strong>&#8220;,<br>                 &#8220;arn:aws:s3:::<strong>SOURCE_BUCKET_NAME<\/strong>\/<em>&#8221;             <\/em><br><em>              ]<\/em><br><em>         },         <\/em><br><em>         {             <\/em><br><em>            &#8220;Effect&#8221;: &#8220;Allow&#8221;,<\/em><br><em>             &#8220;Action&#8221;: [<\/em><br><em>                 &#8220;s3:ListBucket&#8221;,<\/em><br><em>                 &#8220;s3:PutObject&#8221;,<\/em><br><em>                 &#8220;s3:PutObjectAcl&#8221;<\/em><br><em>             ],<\/em><br><em>             &#8220;Resource&#8221;: [<\/em><br><em>                 &#8220;arn:aws:s3:::<\/em><strong>DESTINATION_BUCKET_NAME<\/strong><em>&#8220;,<\/em><br><em>                 &#8220;arn:aws:s3:::<\/em><strong>DESTINATION_BUCKET_NAME<\/strong><em><strong>\/<\/strong><\/em>&#8220;<br>             ]<br>         }<br>     ]<br> }<\/p>\n\n\n\n<p>Replace <strong>DESTINATION_BUCKET_NAME <\/strong> with the actual bucket name of the destination.  Replace the <strong>SOURCE_BUCKET_NAME<\/strong> with the actual source bucket name.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Sync the S3 from AWS CLI<\/h4>\n\n\n\n<p class=\"has-text-color has-very-dark-gray-color\">Using AWS CLI on your computer issue the following command after replacing the BUCKET_NAME with the appropriate actual names.<br>Its important to use destination AWS IAM user account credentials.<\/p>\n\n\n\n<p class=\"has-text-color has-small-font-size has-luminous-vivid-orange-color\">aws s3 sync s3:\/\/SOURCE-BUCKET-NAME s3:\/\/DESTINATION-BUCKET-NAME &#8211;source-region SOURCE-REGION-NAME &#8211;region DESTINATION-REGION-NAME<\/p>\n\n\n\n<p>This would sync the S3 buckets. As usual use due diligence before using this on your production system.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This will show you how to copy objects between S3 buckets across different AWS Accounts. Its not an easy drag and drop. Not sure why Amazon doesn&#8217;t provide an easy &#8220;SFTP&#8221; like feature. Here are the steps: Prerequisites You would need access to both the AWS accounts You need IAM user access on the destination [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1602,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","site-transparent-header":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[961,358,1,962],"tags":[686,960],"class_list":["post-1599","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","category-how-to","category-misc","category-s3","tag-aws","tag-s3"],"_links":{"self":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/1599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1599"}],"version-history":[{"count":10,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/1599\/revisions"}],"predecessor-version":[{"id":1613,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/1599\/revisions\/1613"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/media\/1602"}],"wp:attachment":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}