Skip to content

Instantly share code, notes, and snippets.

@neilmiddleton
Created October 16, 2015 15:24
Show Gist options
  • Save neilmiddleton/98c4252b3ee7b71393d0 to your computer and use it in GitHub Desktop.
Save neilmiddleton/98c4252b3ee7b71393d0 to your computer and use it in GitHub Desktop.
creds = {
"AWS_ACCESS_KEY_ID" => 'foo',
"AWS_SECRET_ACCESS_KEY" => "foo"
}
require 'aws4'
require 'pp'
require 'faraday'
require 'json'
require 'time'
# create a signer
signer = AWS4::Signer.new(
access_key: creds['AWS_ACCESS_KEY_ID'],
secret_key: creds['AWS_SECRET_ACCESS_KEY'],
region: "us-east-1"
)
# build request
headers = {
"Date" => Time.now.iso8601,
"Content-Type" => "application/x-amz-json-1.0",
"host" => "search-heroku-support-lrvw3kyqlzblfmcjcluus2rn74.us-east-1.es.amazonaws.com"
}
body="{}"
# sign headers
uri = URI("https://search-heroku-support-lrvw3kyqlzblfmcjcluus2rn74.us-east-1.es.amazonaws.com/_cat/health")
headers_signed = signer.sign("GET", uri, headers, body, true)
pp headers_signed
conn = Faraday.new(:url => "https://search-heroku-support-lrvw3kyqlzblfmcjcluus2rn74.us-east-1.es.amazonaws.com/")
resp = conn.get do |req|
req.url '/_cat/health'
req.headers = headers_signed
end
pp resp.status
pp resp.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment