Last active
August 1, 2018 12:05
-
-
Save dtelaroli/78339074c0e948114cfa10948dce2582 to your computer and use it in GitHub Desktop.
AWS API Gateway Client Exemple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * | |
| * Install composer | |
| * curl -sS https://getcomposer.org/installer | php | |
| * | |
| * Download AWS SDK | |
| * php composer.phar require aws/aws-sdk-php | |
| * | |
| * References: | |
| * https://forums.aws.amazon.com/thread.jspa?threadID=260049 | |
| * https://docs.aws.amazon.com/pt_br/sdk-for-php/v3/developer-guide/getting-started_installation.html | |
| */ | |
| require 'vendor/autoload.php'; | |
| use Aws\Credentials\Credentials; | |
| use GuzzleHttp\Client; | |
| use GuzzleHttp\Psr7\Request; | |
| use Aws\Signature\SignatureV4; | |
| $access_key = '<define the access key>'; | |
| $secret_key = '<define the secret key'; | |
| $region = 'us-east-1'; | |
| $credentials = new Credentials($access_key, $secret_key); | |
| $client = new Client(); | |
| $url = '<define the endpoint>'; | |
| $headers = [ | |
| '<your header key' => '<your header value>' | |
| ]; | |
| $body = '<body>'; | |
| $request = new Request('POST', $url, $headers, $body); | |
| // $request = new Request('GET', $url); | |
| $s4 = new SignatureV4("execute-api", $region); | |
| $signedrequest = $s4->signRequest($request, $credentials); | |
| $response = $client->send($signedrequest); | |
| echo $response->getBody(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment