Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the documentation for creating s3 bucket to address the region mismatch issue. #4337

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions docs/source/guide/s3-example-creating-buckets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ or to address regulatory requirements.
from botocore.exceptions import ClientError


def create_bucket(bucket_name, region=None):
def create_bucket(bucket_name, region='us-east-1'):
"""Create an S3 bucket in a specified region

If a region is not specified, the bucket is created in the S3 default
Expand All @@ -47,20 +47,16 @@ or to address regulatory requirements.

# Create bucket
try:
if region is None:
s3_client = boto3.client('s3')
s3_client.create_bucket(Bucket=bucket_name)
else:
s3_client = boto3.client('s3', region_name=region)
location = {'LocationConstraint': region}
s3_client.create_bucket(Bucket=bucket_name,
CreateBucketConfiguration=location)
s3_client = boto3.client('s3', region_name=region)
ubaskota marked this conversation as resolved.
Show resolved Hide resolved
location = {'LocationConstraint': region} if region != 'us-east-1' else {}
jonathan343 marked this conversation as resolved.
Show resolved Hide resolved
s3_client.create_bucket(
Bucket=bucket_name, CreateBucketConfiguration=location
)
except ClientError as e:
logging.error(e)
return False
return True


List existing buckets
=====================

Expand All @@ -76,4 +72,3 @@ List all the existing buckets for the AWS account.
print('Existing buckets:')
for bucket in response['Buckets']:
print(f' {bucket["Name"]}')

Loading