r.flipo
r.flipo

Reputation: 135

Laravel Scout config AWS elasticSearch service

Having some issues configuring scout with my AWS ES,

here is my scout.php config :

'elasticsearch' => [
        'index' => 'yyy',

        'config' => [
            'hosts' => [
                [
                    'host' => search-yyy.eu-west-1.es.amazonaws.com,
                    'port' => 80,
                    'scheme' => 'https',
                    'user' => 'myIAM-UserName',
                    'pass' => 'myIAM-secret',
                ],
            ],
        ],
    ],

And i configured my ES access policy like this :

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": [
          "arn:aws:iam::XXX:user/myIAM-user",
          "arn:aws:iam::XXX:root"
        ]
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:eu-west-1:XXX:domain/yyy/*"
    }
  ]
}

It looks like i can't connect (i'm getting the following error) :

No alive nodes found in your cluster

Anyone who made this work could help me ?

Upvotes: 2

Views: 3279

Answers (1)

b3n
b3n

Reputation: 1324

As mentioned here if you want to use IAM credentials with your ES index you will need to sign the requests with AWS Signature Version 4. Fortunately there is already a package that can handle this for you with the elasticsearch/elasticsearch package Scout uses.

So all you need to do is make a new engine that extends ElasticsearchEngine and loads in the handler. Example here: https://gist.github.com/threesquared/65f90c5dda7f6a6fd1afbb6b5089b4ec

Then in your app provider add a custom engine like this:

resolve(EngineManager::class)->extend('signed-elasticsearch', function () {
  return new SignedElasticsearchEngine;
});

Then set scout to use the new driver:

'driver' => 'signed-elasticsearch'

Upvotes: 5

Related Questions