我试图运行查询来检查所有Amazon EC2实例。使用亚马逊AWS sdk - 您无权执行此操作
我使用的演示应用程序模板,它运行良好,我的凭据,但我不太明白它如何使用aws密钥和密钥。
在我的app.config(控制台演示应用程序):
<!-- Amazon AWS API keys. -->
<add key="AWSAccessKey" value="ASDASDASDASD"/>
<add key="AWSSecretKey" value="asdasdf/qwerqwerqwerqwerqwer"/>
<add key="AWSRegion" value="us-east-1" />
它运行良好,并列出我的情况:
// Print the number of Amazon EC2 instances.
IAmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client();
DescribeInstancesRequest ec2Request = new DescribeInstancesRequest();
DescribeInstancesResponse ec2Response = ec2.DescribeInstances(ec2Request);
var numInstances = ec2Response.Reservations.Count;
注意如何它不是真正访问的App.config值这是我混乱的根源。
在实打实的应用
现在,我MVC3应用。我想同样的事情,但我得到这个错误:
You are not authorized to perform this operation.
在我web.config
:
<appSettings>
<!-- Amazon AWS API keys. -->
<add key="AWSAccessKey" value="asdfasdfasdfasdf"/>
<add key="AWSSecretKey" value="adsfasdfadf/asdfasdfasdfasdf"/>
<add key="AWSRegion" value="us-east-1" />
缺少什么我在这里?
如果您创建AWS客户端时未显式提供凭据(即使用无参数构造函数),则SDK将在各个位置查找凭据,其中包括App.config或Web.config的appSettings部分。目前还不清楚为什么他们没有从你的Web.config中获取这种情况。你提供的东西似乎是正确的。 –
我是这样一个混帐 - 我不知道如何/为什么,但由'ConfigurationManager'调用的实际字符串值不正确。我花了3个小时才注意到使用调试器。一些摩卡的时间! – sergserg