Search code examples
apiamazon-cloudfront

How do I do a POST request on Amazon cloudfront API


How do I do a POST control request to the Amazon cloudfront API? In the docs it says:

Send a CloudFront control API request that is similar to the following example.

POST /2012-05-05/origin-access-identity/cloudfront HTTP/1.1
[Required headers]  

<?xml version="1.0" encoding="UTF-8"?>
<CloudFrontOriginAccessIdentityConfig xmlns="http://cloudfront.amazonaws.com/doc/2012-05-05/">
  <CallerReference>20120229090000</CallerReference>   
  <Comment>Your comments here</Comment>
</CloudFrontOriginAccessIdentityConfig>

I looked around for some information, and I am not sure how to do it. Is it something I can do via a Curl Request like here?

Any help very appreciated! I feel a little lost at the moment.

Many thanks!

Update

I do something like this now, still not working.. Any help?

<?php
$xml = 'POST /2012-05-05/origin-access-identity/cloudfront HTTP/1.1
Host: cloudfront.amazonaws.com
Authorization: [AWS authentication string]
Date: [time stamp]
[Other required headers]    

<?xml version="1.0" encoding="UTF-8"?>
<CloudFrontOriginAccessIdentityConfig xmlns="http://cloudfront.amazonaws.com/doc/2012-05-05/">
   <CallerReference>ref</CallerReference>
   <Comment>The comment.</Comment>
</CloudFrontOriginAccessIdentityConfig>
';

$opts = array(
    'http'=>array(
        'method'=>'POST',
        'header'=>"Content-Type: text/plain\r\n" .
            $auth."\r\n",
        'content'=>$xml
    )
);

$context = stream_context_create($opts);
$url = 'https://cloudfront.amazonaws.com/2012-05-05/origin-access-identity/cloudfront';
$fp = fopen($url, 'r', false, $context);
fpassthru($fp);
$response = stream_get_contents($fp);
print_r($response);
fclose($fp);
?>

Solution

  • FireFox add-on Poster must help. https://addons.mozilla.org/en-US/firefox/addon/poster/ Other similar tools: Are there Firefox extension (or any other browser) that allow to send arbitrary POST data to a webpage?