0
0

More than 1 year has passed since last update.

【サンプルコード】aws sdk phpでec2 instance profileを使ってapi gatewayへリクエストする

Posted at
<?php

require './vendor/autoload.php';

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

$method = 'GET';
$region = 'ap-northeast-1';
$stage = 'prod';
$apiName = '/testApi';
$resource = '/test';
$queryAgrs = '?test=1';
$headers = [];
$body = null;
$protocol = '1.1';
$url = 'https://xxxxxx.execute-api.' . $region . '.amazonaws.com/' . $stage . $apiName . $resource . $queryAgr;

$request = new Request($method, $url, $headers, null, $body, $protocol);
$provider = CredentialProvider::instanceProfile();
$credentials = $provider()->wait();
$sigv4 = new SignatureV4('execute-api', $region);
$ret = $sigv4->signRequest($request, $credentials);

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0