<?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);
More than 1 year has passed since last update.
【サンプルコード】aws sdk phpでec2 instance profileを使ってapi gatewayへリクエストする
Posted at
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme