This Python example shows you how to:
In this example, Python code is used to obtain a list of existing Amazon S3 buckets, create a bucket, and upload a file to a specified bucket. The code uses the AWS SDK for Python to get information from and upload files to an Amazon S3 bucket using these methods of the Amazon S3 client class:
All the example code for the Amazon Web Services (AWS) SDK for Python is available here on GitHub.
To set up and run this example, you must first complete this task:
List all the buckets owned by the authenticated sender of the request.
The example below shows how to:
import boto3
# Create an S3 client
s3 = boto3.client('s3')
# Call S3 to list current buckets
response = s3.list_buckets()
# Get a list of all bucket names from the response
buckets = [bucket['Name'] for bucket in response['Buckets']]
# Print out the bucket list
print("Bucket List: %s" % buckets)
The example below shows how to:
import boto3
s3 = boto3.client('s3')
s3.create_bucket(Bucket='my-bucket')
The example below shows how to:
import boto3
# Create an S3 client
s3 = boto3.client('s3')
filename = 'file.txt'
bucket_name = 'my-bucket'
# Uploads the given file using a managed uploader, which will split up large
# files automatically and upload parts in parallel.
s3.upload_file(filename, bucket_name, filename)