AWS SDK for PHP
Developer Guide

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

Signing Custom Amazon CloudSearch Domain Requests with AWS SDK for PHP Version 3

Amazon CloudSearch domain requests can be customized beyond what is supported by the AWS SDK for PHP. In cases where you need to make custom requests to domains protected by IAM authentication, you can use the SDK's credential providers and signers to sign any PSR-7 request.

For example, if you're following Cloud Search's Getting Started guide and want to use an IAM-protected domain for Step 3, you would need to sign and execute your request as follows.

The following examples show how to:

  • Sign a request with the AWS signing protocol using SignatureV4.

All the example code for the AWS SDK for PHP Version 3 is available here on GitHub.

Credentials

Before running the example code, configure your AWS credentials, as described in Credentials for the AWS SDK for PHP Version 3. Then import the AWS SDK for PHP, as described in Basic Usage Patterns of the AWS SDK for PHP Version 3.

Sign CSlong Domain Request

Imports

use Aws\Credentials\CredentialProvider; use Aws\Signature\SignatureV4; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request;

Sample Code

// Prepare a CloudSearch domain request $request = new Request( 'GET', 'https://<your-domain>.<region-of-domain>.cloudsearch.amazonaws.com/2013-01-01/search?q=star+wars&return=title' ); // Get your credentials from the environment $credentials = call_user_func(CredentialProvider::defaultProvider())->wait(); // Construct a request signer $signer = new SignatureV4('cloudsearch', '<region-of-domain>'); // Sign the request $request = $signer->signRequest($request, $credentials); // Send the request $response = (new Client)->send($request); $results = json_decode($response->getBody()); if ($results->hits->found > 0) { echo $results->hits->hit[0]->fields->title . "\n"; }