Can any one tell an idea to create a query for describing regions in aws ec2.I confused in &authparameters .Also please give a program to generate signature .
After a longtime search i found a program that will create a query and returns the response from AWS..It works fine..
Program
<?php
$key='Your aws key';
$pwd='Your AWS secret key';
// See docs ://docs.amazonwebservices.com/AWSEC2/latest/APIReference/------->Actions---->Describe Regions
//for making a request to the aws
$params = array(
'Action' => 'DescribeAvailabilityZones',
'AWSAccessKeyId' => $key,
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
'Version' => '2008-05-05',
'ZoneName.0' => 'us-east-1a',
'ZoneName.1' => 'us-east-1b',
'ZoneName.2' => 'us-east-1c',
'SignatureVersion' => 2,
'SignatureMethod' => 'HmacSHA256'
);
uksort($params, 'strnatcmp');
$qstr = '';
foreach ($params as $key => $val) {
$qstr .= "&{$key}=".rawurlencode($val);
}
$qstr = substr($qstr, 1);
// Signature Version 2
$str = "GET
"
. "ec2.amazonaws.com
"
. "/
"
. $qstr;
$params['Signature'] = base64_encode( hash_hmac('sha256', $str, $pwd, true) ); // Generating a base64-encoded RFC
//2104-compliant HMAC-SHA256
$req = 'https://ec2.amazonaws.com/?' . http_build_query( $params ); // encoded query string
echo '<a href="'.$req.'">XML</a><p>';//For Navigating or creating a request.
?>
You should probably just use the AWS SDK for PHP to handle this stuff for you; it'll make your code nicer, they're far less likely to contain bugs, and it'll save you time in the long run.
The answer here by 'prathyush' is very handy information. I've been searching for a while now for info on how to run an instance on ec2 via an http request with php. This bit of php code can be adapted to do just that and more!
For example replace the $params section with:
$params = array(
'Action' => 'RunInstances', 'ImageId' => 'ami-f0f61599', 'Placement.AvailabilityZone' => 'us-east-1a', 'InstanceType' =>'m1.large', 'MinCount' => '1', 'MaxCount' => '1', 'KeyName' => 'yourkeypair', 'AWSAccessKeyId' => $key, 'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'), 'Version' => '2008-05-05',
'SignatureVersion' => 2,
'SignatureMethod' => 'HmacSHA256' );
Don't forget to change the availability zone above to what you need. For me I changed it to eu-west-1a.
Also change ec2.amazonaws.com to eu-west-1.ec2.amazonaws.com in the two places it appears in the bottom bit of the code.