Python3 boto3 put object to s3 1

Python3 boto3 put object to s3

# Boto 2.x
from boto.s3.key import Key
key = Key('hello.txt')
key.set_contents_from_file('/tmp/hello.txt')

# Boto 3
s3.Object('mybucket', 'hello.txt').put(Body=open('/tmp/hello.txt', 'rb'))

Here is what the above code is Doing:
1. Create a new key object.
2. Set the contents of the key to the contents of the file.
3. Create a new object in the bucket.
4. Set the contents of the object to the contents of the file.

The first example is using the Boto 2.x API and the second example is using the Boto 3 API.

The Boto 2.x API is still available in Boto 3, but it has been renamed.

Similar Posts