Theo
Theo

Reputation: 63

Elasticsearch issue: Cannot connect AWS elasticsearch service

I have a issue about configure elasticsearch to connect AWS elasticsearch service to run project in production. My Gemfile:

    gem 'searchkick'
    gem 'faraday_middleware-aws-signers-v4'
    gem 'aws-sdk', '~> 2'
    gem "elasticsearch", ">= 1.0.15"

Reference: https://github.com/ankane/searchkick

My config/initializers/elasticsearch.rb file:

    require "faraday_middleware/aws_signers_v4"
    ENV["ELASTICSEARCH_URL"] = "https://search-eaterybot-u3yjm6cdn3ogkmv3bcdl5j7poy.ap-southeast-1.es.amazonaws.com/"

       Searchkick.client = Elasticsearch::Client.new(
       url: ENV["ELASTICSEARCH_URL"],
        transport_options: {request: {timeout: 10}}
       ) do |f|
       f.request :aws_signers_v4, {credentials: Aws::Credentials.new(Rails.application.secrets.aws_access_key_id, Rails.application.secrets.aws_secret_access_key),
       service_name: "es",
       region: "ap-southeast-1"
     }
   end

When I run "rake searchkick:reindex:all", it show error:

Elasticsearch::Transport::Transport::Errors::Forbidden: [403] {"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.\n\nThe Canonical String for this request should have been\n'GET\n/_aliases\n\naccept-encoding:gzip;q=1.0,deflate;q=0.6,identity;q=0.3\nhost:search-eaterybot-u3yjm6cdn3ogkmv3bcdl5j7poy.ap-southeast-1.es.amazonaws.com\nx-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\nx-amz-date:20160914T095023Z\n\naccept-encoding;host;x-amz-content-sha256;x-amz-date\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'\n\nThe String-to-Sign should have been\n'AWS4-HMAC-SHA256\n20160914T095023Z\n20160914/ap-southeast-1/es/aws4_request\n47bc69b4440a13aeac990b8c6c49934f1dcc4693bbbda577bfdeb02e685c507b'\n"}"

Anyone can help me! Thanks!

Upvotes: 6

Views: 1730

Answers (1)

Dmitriy Budnik
Dmitriy Budnik

Reputation: 1576

You should exclude tailing slash from ELASTICSEARCH_URL

Upvotes: 8

Related Questions