AWS签名生成

时间:2018-01-12 12:15:53

标签: amazon-web-services

如何生成AWS签名以从AWS URL获取数据?

我有以下凭据。

$AWS_ACCESS_KEY_ID = 'XXXXXXXXXXXX';
$AWS_SECRET_ACCESS_KEY = 'XXXXXXXXXXXXXXXXXX';

以下网址

url="https://ow9hw5rtpk.execute-api.us-west-2.amazonaws.com/dev/getOrderStatus?order_id=XXXXX&zip=XXXX";

我必须从上面的网址中获取数据。我在几个帖子中用cUrl在php中尝试了一些代码,但是没有得到预期的json格式化输出。

当我运行从postman测试界面获得的以下代码时,我得到输出,但签名是静态的。请添加或编辑以下代码以生成动态aws签名。

<?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);
?>

1 个答案:

答案 0 :(得分:0)

看起来x-amz-content-sha256中缺少Authorization,所以添加之后下面的东西也会改变(sha256的值将通过functions-SDK生成) 来自

SignedHeaders=content-type;host;x-amz-date

SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date

一般来说,我鼓励使用 SDKs provided by AWS

准备 Auth 标头