I'm attempting to run what seems like a simple script, but I continue to get an error. If anyone can point out what I'm missing I would be very grateful.
Please note that I know I shouldn't put the keys directly in the script and that I know it's not the best Python written, but this is just a test so I can learn how to do all of this.
The script:
import boto
def s3test():
s3 = boto.connect_s3('MY_ACCESS_KEY', 'MY_SECRET_KEY')
bucket = s3.get_bucket('the-bucket-name')
bucket.copy_key('location1/item',bucket,'location2/item')
if __name__ == "__main__":
s3test()
The error:
Traceback (most recent call last):
File "script/path", line 9, in <module>
s3test()
File "script/path", line 6, in s3test
bucket.copy_key('location1/item',bucket,'location2/item')
File "C:\Python27\lib\site-packages\boto\s3\bucket.py", line 889, in copy_key
response.reason, body)
S3ResponseError: S3ResponseError: 404 Not Found
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist</Message>
<BucketName><Bucket: the-test-bucket></BucketName>
<RequestId>ABCDEFG12345</RequestId>
<HostId>HTLIxTQI87qC56FG2c0y570E+Y2L56e7806OJhAXk2x5i7uzfd4XU/nhmjHVpLqz9</HostId>
</Error>
There are few issues in your code.
Use bucket name
, not bucket object
in copy-key
arguments. And you switched source and destination key order.
copy_key(new_key_name, src_bucket_name, src_key_name)
bucket.copy_key('location2/item','the-bucket-name','location1/item')
should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With