AWS Code Sample


SignDomainRequest.php demonstrates how to sign a custom Amazon CloudSearch Domain Request.

<?php /** * Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. * * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * * * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * ABOUT THIS PHP SAMPLE: This sample is part of the SDK for PHP Developer Guide topic at * * */ use Aws\Credentials\CredentialProvider; use Aws\Signature\SignatureV4; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; /** * Sign Custom Amazon CloudSearch Domain Request. * * This code expects that you have AWS credentials set up per: * */ // Create the client // Prepare a CloudSearch domain request $request = new Request( 'GET', 'https://<your-domain>.<region-of-domain>' ); // 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"; }

Sample Details

Service: cloudsearch

Last tested:

Author: jschwarzwalder (AWS)

Type: full-example

On this page: