Skip to content

Commit 024ad9a

Browse files
authored
Format examples in presigned urls guide (#4483)
1 parent 272ed7e commit 024ad9a

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

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

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ when the URL is generated.
4343
# Generate a presigned URL for the S3 object
4444
s3_client = boto3.client('s3')
4545
try:
46-
response = s3_client.generate_presigned_url('get_object',
47-
Params={'Bucket': bucket_name,
48-
'Key': object_name},
49-
ExpiresIn=expiration)
46+
response = s3_client.generate_presigned_url(
47+
'get_object',
48+
Params={'Bucket': bucket_name, 'Key': object_name},
49+
ExpiresIn=expiration,
50+
)
5051
except ClientError as e:
5152
logging.error(e)
5253
return None
@@ -63,7 +64,7 @@ perform a GET request.
6364

6465
.. code-block:: python
6566
66-
import requests # To install: pip install requests
67+
import requests # To install: pip install requests
6768
6869
url = create_presigned_url('amzn-s3-demo-bucket', 'OBJECT_NAME')
6970
if url is not None:
@@ -92,8 +93,9 @@ the appropriate method so this argument is not normally required.
9293
from botocore.exceptions import ClientError
9394
9495
95-
def create_presigned_url_expanded(client_method_name, method_parameters=None,
96-
expiration=3600, http_method=None):
96+
def create_presigned_url_expanded(
97+
client_method_name, method_parameters=None, expiration=3600, http_method=None
98+
):
9799
"""Generate a presigned URL to invoke an S3.Client method
98100
99101
Not all the client methods provided in the AWS Python SDK are supported.
@@ -108,10 +110,12 @@ the appropriate method so this argument is not normally required.
108110
# Generate a presigned URL for the S3 client method
109111
s3_client = boto3.client('s3')
110112
try:
111-
response = s3_client.generate_presigned_url(ClientMethod=client_method_name,
112-
Params=method_parameters,
113-
ExpiresIn=expiration,
114-
HttpMethod=http_method)
113+
response = s3_client.generate_presigned_url(
114+
ClientMethod=client_method_name,
115+
Params=method_parameters,
116+
ExpiresIn=expiration,
117+
HttpMethod=http_method,
118+
)
115119
except ClientError as e:
116120
logging.error(e)
117121
return None
@@ -134,8 +138,9 @@ request and requires additional parameters to be sent as part of the request.
134138
from botocore.exceptions import ClientError
135139
136140
137-
def create_presigned_post(bucket_name, object_name,
138-
fields=None, conditions=None, expiration=3600):
141+
def create_presigned_post(
142+
bucket_name, object_name, fields=None, conditions=None, expiration=3600
143+
):
139144
"""Generate a presigned URL S3 POST request to upload a file
140145
141146
:param bucket_name: string
@@ -152,11 +157,13 @@ request and requires additional parameters to be sent as part of the request.
152157
# Generate a presigned S3 POST URL
153158
s3_client = boto3.client('s3')
154159
try:
155-
response = s3_client.generate_presigned_post(bucket_name,
156-
object_name,
157-
Fields=fields,
158-
Conditions=conditions,
159-
ExpiresIn=expiration)
160+
response = s3_client.generate_presigned_post(
161+
bucket_name,
162+
object_name,
163+
Fields=fields,
164+
Conditions=conditions,
165+
ExpiresIn=expiration,
166+
)
160167
except ClientError as e:
161168
logging.error(e)
162169
return None
@@ -172,7 +179,7 @@ presigned POST URL to perform a POST request to upload a file to S3.
172179

173180
.. code-block:: python
174181
175-
import requests # To install: pip install requests
182+
import requests # To install: pip install requests
176183
177184
# Generate a presigned S3 POST URL
178185
object_name = 'OBJECT_NAME'

0 commit comments

Comments
 (0)