Skip to content

Instantly share code, notes, and snippets.

@andresriancho
Created March 5, 2025 19:36
Show Gist options
  • Save andresriancho/ec8b03788f6e00c55e36363ee8c51ce7 to your computer and use it in GitHub Desktop.
Save andresriancho/ec8b03788f6e00c55e36363ee8c51ce7 to your computer and use it in GitHub Desktop.
Inspecting boto3 HTTP traffic
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