Created
October 18, 2018 01:05
-
-
Save TonyFNZ/af239342a22218334c68cb95414b9c7b to your computer and use it in GitHub Desktop.
This script will download a file from a S3 bucket in one AWS account and stream it directly into another S3 bucket in another account. File is streamed as it arrives, so memory usage is low (typically <100MB)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/python | |
# This script will download a file from a S3 bucket in one AWS account | |
# and stream it directly into another S3 bucket in another account. | |
# File is streamed as it arrives, so memory usage is low (typically <100MB) | |
import boto3 | |
# Create two S3 clients, one in each AWS account | |
# If wanting to use an instance role for one client, remove the access key parameters | |
s3_source = boto3.client( | |
's3', | |
aws_access_key_id='<Access Key Account A>', | |
aws_secret_access_key='<Secret Access Key Account A>', | |
aws_session_token='<Session Token Account A>' | |
) | |
s3_target = boto3.client( | |
's3', | |
aws_access_key_id='<Access Key Account B>', | |
aws_secret_access_key='<Secret Access Key Account B>', | |
aws_session_token='<Session Token Account B>' | |
) | |
# Change these to target the file you want | |
sourceBucket = '<Source S3 Bucket>' | |
sourceKey = '<Source Filename/Key>' | |
targetBucket = '<Target S3 Bucket>' | |
targetKey = '<Target Filename/Key>' | |
obj = s3_source.get_object( Bucket=sourceBucket, Key=sourceKey ) | |
s3_target.upload_fileobj(obj['Body'], targetBucket, targetKey) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment