Last active
April 16, 2019 20:23
-
-
Save dslaw/bb6010938d760f84a9ded8808b269ad6 to your computer and use it in GitHub Desktop.
Example demonstrating how to inspect canonical HTTP requests to S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
s3_client = boto3.client("s3") | |
# List available operations. | |
s3_client._service_model.operation_names | |
operation_name = "ListObjectsV2" | |
params = { | |
"Bucket": "my-bucket", | |
"Prefix": "path/to/somewhere", | |
"MaxKeys": 100, | |
} | |
# From `s3_client._make_api_call`. | |
operation_model = s3_client._service_model.operation_model(operation_name) | |
request_context = { | |
"client_region": s3_client.meta.region_name, | |
"client_config": s3_client.meta.config, | |
"has_streaming_input": operation_model.has_streaming_input, | |
"auth_type": operation_model.auth_type, | |
} | |
request_dict = s3_client._convert_to_request_dict( | |
params, | |
operation_model, | |
context=request_context | |
) | |
handler, event_response = s3_client.meta.events.emit_until_response( | |
"before-call.{endpoint_prefix}.{operation_name}".format( | |
endpoint_prefix=client._service_model.endpoint_prefix, | |
operation_name=operation_name, | |
), | |
model=operation_model, params=request_dict, | |
request_signer=client._request_signer, context=request_context) | |
if event_response is None: | |
http, parsed_response = s3_client._endpoint.make_request( | |
operation_model, request_dict) | |
# XML response. | |
print(http.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment