简体   繁体   English

亚马逊ec2查询

[英]amazon ec2 query making

任何人都可以说出一个想法来创建描述aws ec2中区域的查询。我对&authparameters感到困惑。还请提供一个程序来生成签名。

After a longtime search i found a program that will create a query and returns the response from AWS..It works fine.. 经过长时间的搜索,我找到了一个程序,该程序将创建查询并从AWS返回响应。

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\n"  
 . "ec2.amazonaws.com\n"
 . "/\n"      
 . $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; 您可能应该只使用适用于PHPAWS开发工具包为您处理这些工作; 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. 这里的“ prathyush”答案非常有用。 I've been searching for a while now for info on how to run an instance on ec2 via an http request with php. 我一直在搜索一段时间,以获取有关如何通过php的http请求在ec2上运行实例的信息。 This bit of php code can be adapted to do just that and more! 这段php代码可以适应于完成更多操作!

For example replace the $params section with: 例如,将$ params部分替换为:

$params = array( $ params =数组(
'Action' => 'RunInstances', 'ImageId' => 'ami-f0f61599', 'Placement.AvailabilityZone' => 'us-east-1a', 'InstanceType' =>'m1.large', 'MinCount' => '1', 'MaxCount' => '1', 'KeyName' => 'yourkeypair', 'AWSAccessKeyId' => $key, 'Timestamp' => gmdate('Ymd\\TH:i:s\\Z'), 'Version' => '2008-05-05', 'Action'=>'RunInstances','ImageId'=>'ami-f0f61599','Placement.AvailabilityZone'=>'us-east-1a','InstanceType'=>'m1.large','MinCount'= >'1','MaxCount'=>'1','KeyName'=>'yourkeypair','AWSAccessKeyId'=> $ key,'Timestamp'=> gmdate('Ymd \\ TH:i:s \\ Z') ,'版本'=>'2008-05-05',
'SignatureVersion' => 2, 'SignatureVersion'=> 2,
'SignatureMethod' => 'HmacSHA256' ); 'SignatureMethod'=>'HmacSHA256');

Don't forget to change the availability zone above to what you need. 不要忘记将上方的可用区域更改为您所需的内容。 For me I changed it to eu-west-1a. 对我来说,我将其更改为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. 同样,将ec2.amazonaws.com更改为eu-west-1.ec2.amazonaws.com,将其显示在代码底部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM