DEV Community

S3CloudHub
S3CloudHub

Posted on

Create S3 Bucket using Python Boto3

S3 Operation using Python Boto3 like Create Bucket, Delete Bucket, Upload File, Delete File, and list Buckets

BOTO3 Installation
pip install boto3

AWS Configuration

Before using Boto3, you need to set up authentication credentials for your AWS account using either the IAM Console or the AWS CLI. You can either choose an existing user or create a new one.
If you have the AWS CLI installed, then you can use the AWS configure command to configure your credentials file.

aws configure

Boto3 Configuration

To use Boto3, you must first import it and indicate which service or services you're going to use
import boto3
# Reference for Amazon S3 Resource
s3 = boto3.resource('s3')

Client and Resource are two different abstractions within the boto3 SDK for making AWS service requests. You would typically choose to use either the Client abstraction or the Resource abstraction. I've outlined the differences between Client and Resource below to help readers decide which to use.

import boto3
# Reference for Amazon S3 Resource
client = boto3.client('s3')

List S3 Bucket Example using client

import boto3
client = boto3.client('s3')
list_bucket=client.list_buckets()
for bucket in list_bucket['Buckets']:
print(bucket['Name'])

Top comments (0)