phplaravelopensearchamazon-opensearch

AWS Open Search Managed Cluster - No Alive Nodes


I am using Laravel 8 with a Provider singleton to instantiate Open Search so I can use it within other parts of the application easily by calling the singleton.

I am using the Open Search provided SDK found here: https://opensearch.org/docs/latest/clients/php/

I'm using some pretty basic code for my local coding environment where I have a docker container running of Open Search with the basic admin/admin username:password combo that it comes with.

        $this->app->singleton(OpenSearch::class, function ($app) {
            return (new \OpenSearch\ClientBuilder())
                ->setHosts([Config::get('search.endpoint')])
                ->setBasicAuthentication(Config::get('search.username'), Config::get('search.password'))
                ->setSSLVerification(false)
                ->build();
        });

My Managed Cluster uses a similar setup with username/password.

If I use postman, I can see the health using _cat/health?v.

I can even create an index using the PUT method via Postman. However, I am having trouble doing so with Laravel and the SDK code.

Note: This all works with a localhost:9200/ setup, just not with the aws managed cluster.

I've tried adding some debugging into the application but I just get "No Nodes Alive" message which seems to me that it is not properly connecting to the service.

Anyone else had similar experiences?

My "production ready" code does not include the ->setSSLVerification as it needs to verify the SSL.

I've validated that Postman is able to create the index. I've tried adding in additional logging to get info() of the service:

        $this->app->singleton(OpenSearch::class, function ($app) {
            $client = (new \OpenSearch\ClientBuilder())
                ->setHosts([Config::get('search.endpoint')])
                ->setBasicAuthentication(Config::get('search.username'), Config::get('search.password'))
                ->build();

            echo "<pre>";
            print_r($client->info());
            echo "</pre>";
            die();
        });

It takes about 5 minutes to eventually die and this is what I'm left with in the console:

<pre>
   OpenSearch\Common\Exceptions\NoNodesAvailableException 

  No alive nodes found in your cluster

  at vendor/opensearch-project/opensearch-php/src/OpenSearch/ConnectionPool/StaticNoPingConnectionPool.php:67
     63▕                 return $connection;
     64▕             }
     65▕         }
     66▕ 
  ➜  67▕         throw new NoNodesAvailableException("No alive nodes found in your cluster");
     68▕     }
     69▕ 
     70▕     public function scheduleCheck(): void
     71▕     {

      +11 vendor frames 
  12  app/Providers/SearchServiceProvider.php:25
      OpenSearch\Client::info()

      +6 vendor frames 
  19  app/Search/OpenSearchProvider.php:220
      app("OpenSearch\Client")

Any help would be greatly appreciated. I'm at a loss at this point.


Solution

  • Okay, so a lot of digging into the code and I found that it was defaulting to 9200 even if it is https. I added port :443 to the end of my code url in my environment variables and that ended up solving the problem!

    Something so simple and I didn't think to try that first. Leaving the answer here in case anyone else runs into this problem.