Eavis / CNN

0 stars 0 forks source link

AmazonS3 boto3 #6

Open Eavis opened 5 years ago

Eavis commented 5 years ago

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')

Eavis commented 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)

Eavis commented 5 years ago

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()

Eavis commented 5 years ago

switch python brew info python

brew switch python 3.6.5_1