Creating buckets

The first logical thing to do, when interacting with an AWS S3 service, is create a bucket that can be used to store files. In that case, we will provide the S3 to the boto3.resource() . That will tell the boto3 to start the initialization process and will load required commands to interact with the S3 API system:

import boto3s3_resource = boto3.resource("s3")bucket = s3_resource.create_bucket(Bucket="my_first_bucket", CreateBucketConfiguration={    'LocationConstraint': 'us-west-2'})print(bucket)

In the preceding example, the following applies:

  1. We imported the boto3 module that we installed previously.
  2. Then, we specified a resource type that we wanted to interact with, which is s3, and assigned that to the s3_resource object. ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.