-
-
Save jrgifford/7899e79cf234ec5fc37f5904f908e33f to your computer and use it in GitHub Desktop.
Using Amazon Elasticsearch securely (signed requests) with Rails & searchkick gem on Heroku.
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
# config/initializers/elasticsearch.rb | |
# ensure you set AWS_ES_URL, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY | |
# change region as needed | |
require 'patron' | |
require 'faraday_middleware/aws_signers_v4' | |
# arguably this should be defined elsewhere | |
class AmazonElasticSearchClient | |
def self.client | |
return Elasticsearch::Client.new(url: ENV['AWS_ES_URL']) do |f| | |
f.request :aws_signers_v4, | |
credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']), | |
service_name: 'es', | |
region: 'us-west-2' | |
end | |
end | |
end | |
# for local development I run a local elasticsearch, | |
# so I only override the Searchkick.client in production environments | |
Searchkick.client = AmazonElasticSearchClient.client if Rails.env.production? |
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
gem 'elasticsearch', '>= 1.0.15' | |
gem 'elasticsearch-model' | |
gem 'elasticsearch-rails' | |
gem 'patron' | |
gem 'faraday_middleware-aws-signers-v4' | |
gem 'searchkick' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment