Skip to content

Commit

Permalink
fixes the issue in the example code and rendering the test
Browse files Browse the repository at this point in the history
  • Loading branch information
ubaskota committed Nov 12, 2024
1 parent 12e24d8 commit 72557dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ coverage.xml
venv
env2
env3
boto3_venv/


# Virtualenv support files and directories
.python-version
Expand Down
19 changes: 10 additions & 9 deletions docs/source/guide/s3-example-creating-buckets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ platform. The bucket can be located in a specific region to minimize latency
or to address regulatory requirements.

.. note::
The `LocationConstraint` value is used to specify the region where a bucket
will be created. S3 requires `LocationConstraint` to be specified when creating
buckets using a client in regions other than `us-east-1`. When no region is
specified, `us-east-1` is used by default. The example below ensures the S3
The ``LocationConstraint`` value is used to specify the region where a bucket
will be created. S3 requires ``LocationConstraint`` to be specified when creating
buckets using a client in regions other than ``us-east-1``. When no region is
specified, ``us-east-1`` is used by default. The example below ensures the S3
client is created in the same region as the bucket to avoid a
`IllegalLocationConstraintException` error.
``IllegalLocationConstraintException`` error.

.. code-block:: python
Expand All @@ -55,11 +55,12 @@ or to address regulatory requirements.
# Create bucket
try:
bucket_config = {}
s3_client = boto3.client('s3', region_name=region)
location = {'LocationConstraint': region} if region != 'us-east-1' else {}
s3_client.create_bucket(
Bucket=bucket_name, CreateBucketConfiguration=location
)
if region != "us-east-1":
bucket_config["CreateBucketConfiguration"] = {"LocationConstraint": region}
s3_client.create_bucket(Bucket=bucket_name, **bucket_config)
except ClientError as e:
logging.error(e)
return False
Expand Down

0 comments on commit 72557dc

Please sign in to comment.