Skip to content

Instantly share code, notes, and snippets.

@trevorrowe
Created March 22, 2012 21:34
Show Gist options
  • Save trevorrowe/2164736 to your computer and use it in GitHub Desktop.
Save trevorrowe/2164736 to your computer and use it in GitHub Desktop.
Wrapping the aws-sdk http handler to view raw http requests and responses
# build a dummy http handler that extends the default handler
# that outputs the request body before making the request (via super)
# then check the response body
# req is a AWS::Core::Http::Request object
# resp is a AWS::Core::Http::Response object
default_handler = AWS.config.http_handler
debug_handler = AWS::Core::Http::Handler.new(default_handler) do |req,resp|
puts "REQUEST BODY: #{req.body}"
super(req,resp)
puts "RESPONSE BODY: #{resp.body}"
end
# register the new http handler as the global default
AWS.config(:http_handler => debug_handler)
# make a request and see the request body
ec2 = AWS::EC2.new
ec2.instances.first
# instead of setting the new handler as the global default you can
# also use it selectively
ec2 = AWS::EC2.new(:http_handler => debug_handler)
ec2.instances.first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment