Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkerbot/280299fdab9866cf7e2a3d0448729a4b to your computer and use it in GitHub Desktop.
Save thinkerbot/280299fdab9866cf7e2a3d0448729a4b to your computer and use it in GitHub Desktop.
Sign requests to get access to a role-controlled AWS elasticsearch
require 'aws-sdk'
require 'faraday_middleware'
require 'faraday_middleware/aws_signers_v4'
require 'pp'
conn = Faraday.new(url: 'http://ENDPOINT') do |faraday|
faraday.request :aws_signers_v4,
credentials: Aws::InstanceProfileCredentials.new.credentials,
service_name: 'es',
region: 'REGION'
faraday.response :json, :content_type => /\bjson\b/
faraday.response :raise_error
faraday.adapter Faraday.default_adapter
end
res = conn.get '/'
pp res.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment