Skip to content

Commit ec9b758

Browse files
committed
Presigned URLs generated without addressing_style='virtual' use the
legacy global endpoint (bucket.s3.amazonaws.com), which returns errors for S3 buckets in Regions launched after March 20, 2019. Updated all three code examples (create_presigned_url, create_presigned_url_expanded, create_presigned_post) to include s3={'addressing_style': 'virtual'} in the Config, and updated the recommendation text to mention virtual-hosted-style addressing.
1 parent e73a6f9 commit ec9b758

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

docs/source/guide/s3-presigned-urls.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ A presigned URL remains valid for a limited period of time which is specified
2525
when the URL is generated.
2626

2727
It is recommended to configure the S3 client with Signature Version 4
28-
(``s3v4``) and the AWS region of the bucket when generating presigned URLs.
28+
(``s3v4``), the AWS region of the bucket and to use virtual-hosted style addressing ``s3={'addressing_style': 'virtual'}`` when generating presigned URLs.
2929

3030
.. code-block:: python
3131
@@ -51,7 +51,10 @@ It is recommended to configure the S3 client with Signature Version 4
5151
s3_client = boto3.client(
5252
's3',
5353
region_name=region_name,
54-
config=Config(signature_version='s3v4'),
54+
config=Config(
55+
signature_version='s3v4',
56+
s3={'addressing_style': 'virtual'},
57+
),
5558
)
5659
try:
5760
response = s3_client.generate_presigned_url(
@@ -129,7 +132,10 @@ the appropriate method so this argument is not normally required.
129132
s3_client = boto3.client(
130133
's3',
131134
region_name=region_name,
132-
config=Config(signature_version='s3v4'),
135+
config=Config(
136+
signature_version='s3v4',
137+
s3={'addressing_style': 'virtual'},
138+
),
133139
)
134140
try:
135141
response = s3_client.generate_presigned_url(
@@ -187,7 +193,10 @@ request and requires additional parameters to be sent as part of the request.
187193
s3_client = boto3.client(
188194
's3',
189195
region_name=region_name,
190-
config=Config(signature_version='s3v4'),
196+
config=Config(
197+
signature_version='s3v4',
198+
s3={'addressing_style': 'virtual'},
199+
),
191200
)
192201
try:
193202
response = s3_client.generate_presigned_post(

0 commit comments

Comments
 (0)