亚马逊ec2查询制作

发布于 2024-10-12 14:05:49 字数 87 浏览 1 评论 0原文

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

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 .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦途 2024-10-19 14:05:49

您可能应该使用 AWS SDK for PHP 来为您处理这些事情;它会让你的代码变得更好,它们包含错误的可能性要小得多,从长远来看,它会节省你的时间。

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.

梨涡 2024-10-19 14:05:49

经过长时间的搜索,我找到了一个程序,它将创建一个查询并从AWS返回响应..它工作正常..

程序

<?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.



 ?>

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\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.



 ?>
浅笑依然 2024-10-19 14:05:49

“prathyush”在这里的答案是非常方便的信息。我已经搜索了一段时间有关如何通过使用 php 的 http 请求在 ec2 上运行实例的信息。这段 php 代码经过修改后可以做到这一点甚至更多!

例如,将 $params 部分替换为:

$params = array(
'行动' => '运行实例',
'图像ID' => 'ami-f0f61599',
'Placement.AvailabilityZone' =>; 'us-east-1a',
'InstanceType' => 'm1.large',
'最小计数' => '1',
'最大计数' => '1',
'键名' => '你的密钥对',
'AWSAccessKeyId' => $键,
'时间戳' => gmdate('Ymd\TH:i:s\Z'),
'版本' => '2008-05-05',
'签名版本' => 2、
'签名方法' => 'HmacSHA256'
);

不要忘记将上面的可用区域更改为您需要的。对我来说,我将其更改为 eu-west-1a。

另外,在代码底部出现的两个位置将 ec2.amazonaws.com 更改为 eu-west-1.ec2.amazonaws.com。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文