Created
March 5, 2025 19:36
-
-
Save andresriancho/ec8b03788f6e00c55e36363ee8c51ce7 to your computer and use it in GitHub Desktop.
Inspecting boto3 HTTP traffic
This file contains hidden or 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 | |
import botocore | |
def log_request(request, **kwargs): | |
"""Logs all HTTP requests made by boto3 before they are sent.""" | |
print(f"🔍 Intercepted HTTP request:") | |
print(f" - Method: {request.method}") | |
print(f" - URL: {request.url}") | |
print(f" - Headers: {request.headers}") | |
print(f" - Body: {request.body}\n") | |
# Create a boto3 client (this ensures we are using the correct session) | |
s3 = boto3.client("s3") | |
# Get the botocore session used by boto3 | |
botocore_session = s3._endpoint._event_emitter | |
# Register a listener for ALL outgoing requests | |
botocore_session.register("before-send", log_request) | |
# Call any boto3 function to see intercepted requests | |
s3.list_buckets() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment