This package makes the Elasticsearch driver for Laravel Scout that works with AWS Elasticsearch and IAM.
You can install the package via composer:
composer require matthbon/laravel-scout-elastic-aws
You must add the Scout service provider and the package service provider in your app.php config:
// config/app.php
'providers' => [
...
Laravel\Scout\ScoutServiceProvider::class,
...
ScoutEngines\Elasticsearch\ElasticsearchProvider::class,
],
This package assumes you are following good AWS security and /not/ putting password in your Laravel .env files an instead follows the practices outlined in Credentials for the AWS SDK for PHP Version 3. To enable this, set the following variable in your .env.
ELASTICSEARCH_PROVIDER=aws
For local development, inside vagrant for instance, you can use the normal Elasticsearch client by either omitting this variable or setting it as follows.
ELASTICSEARCH_PROVIDER=elastic
One thing the AWS client needs is the Region. If you don't already have it in your .env, add it as such.
AWS_REGION=us-west-2
For using IAM credentials, add those to .env.
AWS_ACCESS_KEY=
AWS_ACCESS_SECRET=
AWS_ACCESS_TOKEN=
If your CI environment does not have access to a working Elasticsearch instance, any indexed Models will cause it to error. To solve this, add the following to your phpunit.xml. The single quotes wrapping the double quotes are the tricky part there.
<env name="SCOUT_DRIVER" value='"null"' />
After you've published the Laravel Scout package configuration
php artisan vendor:publish --provider="ScoutEngines\Elasticsearch\ElasticsearchProvider"
you'll need to update the main scout configuration
// config/scout.php
// Set your driver to elasticsearch
'driver' => env('SCOUT_DRIVER', 'elasticsearch'),
...
'elasticsearch' => [
'index' => env('ELASTICSEARCH_INDEX', 'laravel'),
'hosts' => [
env('ELASTICSEARCH_HOST', 'http://localhost'),
],
],
...
and this package's configuration
// config/laravel-scout-elastic.php
// set this if you don't want to include it in your .env
'provider' => env('ELASTICSEARCH_PROVIDER', 'elasticsearch'),
...
'region' => env('AWS_REGION', 'us-west-2'),
...
and enable the artisan job:
// App/Console/Kernel.php
protected $commands = [
...
\ScoutEngines\Elasticsearch\Commands\CreateIndex::class,
...
],
Scout will happily throw an error if it cannot create contact your Elasticsearch server or the index doesn't exist.
Creating an index can be kinda arcane, so if the index doesn't exist, you can include the following artisan command in your deployment stack to check if the index exists, and if it doesnt then it will create it.
php artisan scout:create-index
Now you can use Laravel Scout as described in the official documentation
The MIT License (MIT).