php - Setting Authentication for AWS API Gateway -
we have lambda function called aws api gateway. have been trying call php code. using document try 'authorization' header right:
http://docs.aws.amazon.com/amazons3/latest/dev/restauthentication.html#restauthenticationdebugging
but must missing something, because keep getting error:
{"message":"missing authentication token"}
here's have far:
current_date = date('d, d m y h:i:s +u'); $tmp1 = explode('/',aws_url); write_log("url exploded" . json_encode($tmp1)); $tmp2 = explode('.',$tmp1[2]); write_log("ip exploded: " . json_encode($tmp2)); $url_parts = $tmp2[0] . '/' . $tmp1[3] . '/' . $tmp1[4]; $to_cannonicalize = 'post\ncontent-md5\ntontent-type\n' . $current_date . '\n' . $url_parts; write_log("cannocalize string: " . $to_cannonicalize); $signature = base64_encode(hash_hmac('sha256', $to_cannonicalize, aws_labmda_secret)); $formatted_date = date('ymd'); $zdate = date('ymd') . 't' . date('his') . 'z'; $authorization = 'aws ' . aws_labmda_key . ':' . $signature; // set curl call $header_array = array ( 'content-type' => 'application/json', 'authorization' => $authorization, 'x-amz-date' => $zdate ); write_log(json_encode($header_array)); $post_data = array ( 'postalcode' => $zip ); $curl = curl_init( aws_taxrate_url ); curl_setopt( $curl, curlopt_returntransfer, 1 ); curl_setopt( $curl, curlopt_post, 1 ); curl_setopt($curl, curlopt_httpheader, $header_array); curl_setopt( $curl, curlopt_postfields, $post_data ); // make call , send results $curl_response = curl_exec( $curl ); i tried copying being used in postman header (where i'm getting different type of error):
$authorization = 'aws4-hmac-sha256 credential=' . aws_labmda_key . '/' . $formatted_date . '/' . aws_sqs_region . '/execute-api/aws4_request, signedheaders=content-length;content-type;host;x-amz-date, ' . 'signature=' . $signature; that didn't seem work either.
Comments
Post a Comment