Last active
December 20, 2016 17:41
-
-
Save holybit/6035b80bb78a1492ec10400b2104d7d4 to your computer and use it in GitHub Desktop.
Boto3 S3 bucket.copy() not working as documented
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
$ ./test.py | |
archived/prod/20151119/DMARC-AUTH/archive_prod_2015111911_45_0.json.gz | |
Traceback (most recent call last): | |
File "./test.py", line 28, in <module> | |
main() | |
File "./test.py", line 25, in main | |
bucket.copy(copy_source, key) | |
AttributeError: 's3.Bucket' object has no attribute 'copy' | |
# according to the boto3 docs there is a bucket.copy() | |
# https://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.copy |
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
#!/usr/bin/env python | |
import boto3 | |
import sys | |
def main(): | |
boto3.setup_default_session(profile_name='datapipeline') | |
s3 = boto3.resource('s3') | |
source_bucket = 'maelstrom-archive.returnpath.net' | |
target_bucket = 'jcrotty-archive-test' | |
key = 'archived/prod/20151119/DMARC-AUTH/archive_prod_2015111911_45_0.json.gz' | |
print(key) | |
# below code lifted directly from boto3 docs | |
# https://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.copy | |
s3 = boto3.resource('s3') | |
copy_source = { | |
'Bucket': source_bucket, | |
'Key': key | |
} | |
bucket = s3.Bucket(target_bucket) | |
bucket.copy(copy_source, key) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment