Open Eavis opened 5 years ago
source:https://realpython.com/python-boto3-aws-s3/
By using the resource, you have access to the high-level classes (Bucket and Object). This is how you can create one of each:
first_bucket = s3_resource.Bucket(name=first_bucket_name)
first_object = s3_resource.Object( bucket_name=first_bucket_name, key=first_file_name)
Bucket and Object are sub-resources of one another. Sub-resources are methods that create a new instance of a child resource. The parent’s identifiers get passed to the child resource.
first_object_again = first_bucket.Object(first_file_name)
first_bucket_again = first_object.Bucket()
switch python brew info python
brew switch python 3.6.5_1
import boto3 s3 = boto3.resource('s3') for bucket in s3.buckets.all(): print(bucket.name)
To connect to the low-level client interface, you must use Boto3’s client().s3_client = boto3.client('s3')
To connect to the high-level interface, you’ll follow a similar approach, but use resource():s3_resource = boto3.resource('s3')