The s3 is a highly efficient, scalable file storage solution provided by AWS.
The s3 consist of buckets and objects. Buckets are like a folder in the file system and s3 objects are the files we could store in a bucket.
The object consists of keys, values, and metadata.
Key is a unique identifier for the object, value is actual object data and metadata is the data about the data.
To programmatically access s3 we need aws_secret_access_key to access s3, we get it at the time of creating a new user on AWS through IAM or we can re-generate it through AWS IAM.
Introduction to Boto3
Boto3 is the library we can use in Python to interact with s3, Boto3 consists of 2 ways to interact with aws service, either by client or resource object. The major difference between resource and boto3 client is the client is a low level class object and resource is a high-level service class; it’s a wrapper on the boto3 client.
Firstly, we need to create the boto3 session. An AWS credentials session is where to initiate the connectivity to AWS services, the aws_session is optional here.
- def aws_session(region_name=region,id=aws_id,secret=secret):
- return boto3.session.Session(aws_access_key_id=id,
- aws_secret_access_key=secret,
- region_name=region_name,aws_session_token=session_token)
Now we will create s3 client which we will use in the rest of tutorial.
- session = aws_session()
- s3_client = session.client('s3')
Create/Delete/List Bucket
Before we upload any object on s3 we need to create buckets using the following line of code.
- def create_s3_bucket(s3_client,bucket_name,region):
- s3_client.create_bucket(Bucket=bucket_name)
Now list all the buckets we have with the following line of code.
- def list_bucket(s3_client):
- list_of_bucket = s3_client.list_buckets()
- for bucket in list_of_bucket['Buckets']:
- print(f' {bucket["Name"]}')

Join the conversation! Your thoughts help the community grow.