Skip to content

Instantly share code, notes, and snippets.

@holybit
Last active December 20, 2016 17:41
Show Gist options
  • Save holybit/6035b80bb78a1492ec10400b2104d7d4 to your computer and use it in GitHub Desktop.
Save holybit/6035b80bb78a1492ec10400b2104d7d4 to your computer and use it in GitHub Desktop.
Boto3 S3 bucket.copy() not working as documented
$ ./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
#!/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