How can I generate AWS signature for getting data from the AWS url?
I have the following credentials.
$AWS_ACCESS_KEY_ID = 'XXXXXXXXXXXX';
$AWS_SECRET_ACCESS_KEY = 'XXXXXXXXXXXXXXXXXX';
And the following url
url="https://ow9hw5rtpk.execute-api.us-west-2.amazonaws.com/dev/getOrderStatus?order_id=XXXXX&zip=XXXX";
I have to take data from the above url. I tried some code in php with cUrl from several post, but did not get the expected json formatted output.
I get the output when I run the following code that I got from postman test interface, but the signature is a static one. Please add or edit the below code for generating dynamic aws signature.
<?php
$curl = curl_init();
$datestamp = time();
$date = gmdate('D, d M Y H:i:s e',$datestamp);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://ow9hw5rtpk.execute-api.us-west-2.amazonaws.com /dev/getOrderStatus?email=XXX@XXXX.NET&zip=XXXX",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_SSL_VERIFYHOST=>0,
CURLOPT_SSL_VERIFYPEER=>0,
CURLOPT_HTTPHEADER => array(
"Authorization: AWS4-HMAC-SHA256 Credential=AKIAIV4KH3BTCPT3E6FA/20180112/us-west-2/execute-api/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=cf871e46b14f48ef7e08e003250f6fcf7d0a90c5ca29b51ff9f6eae0eb104cdb",
"Cache-Control: no-cache",
"Content-Type: application/x-www-form-urlencoded",
"Postman-Token: 3bea6936-0a81-e723-ee36-9e08a219a975",
"X-Amz-Date: 20180112T110821Z"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
?>
Looks like x-amz-content-sha256
is missing in Authorization
, so after adding that below stuff will also change (value of sha256 will be generated through functions-SDK) from
SignedHeaders=content-type;host;x-amz-date
To
SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date
In general, I would encourage to prepare Auth header with SDKs provided by AWS
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.