Now, we need to make use of the created bucket and upload a file to it. Remember, the file representation inside the bucket is an object. So, boto3 provides some methods that contain the object as a part of it. We will start by using put_object(). This method will upload a file to the created bucket and store it as an object:
import boto3s3_resource = boto3.resource("s3")bucket = s3_resource.Bucket("my_first_bucket")with open('~/test_file.txt', 'rb') as uploaded_data: bucket.put_object(Body=uploaded_data)
In the preceding example, the following applies:
- We imported the boto3 module that we installed previously.
- Then, we specified a resource type that we wanted to interact with, which is s3, and assigned that ...