Amazon.Runtime.AmazonServiceException:无法找到凭据

我们使用连接到AWS SNS服务的AWS SDK工具包在vs 2010中设计了WebService应用程序。

当我们直接从VS 2010开发工作室运行时,它完美地工作,但是当我们将webservice发布到本地IIS或专用Web服务器时,它失败并显示以下错误消息。

Amazon.Runtime.AmazonServiceException: Unable to find credentials Exception 1 of 4: System.ArgumentException: Path cannot be the empty string or all whitespace. Parameter name: path at System.IO.Directory.GetParent(String path) at Amazon.Runtime.StoredProfileAWSCredentials.DetermineCredentialsFilePath(String profilesLocation) at Amazon.Runtime.StoredProfileAWSCredentials..ctor(String profileName, String profilesLocation) at Amazon.Runtime.EnvironmentAWSCredentials..ctor() at Amazon.Runtime.FallbackCredentialsFactory.<Reset>b__1() at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous) Exception 2 of 4: System.ArgumentException: Path cannot be the empty string or all whitespace. Parameter name: path at System.IO.Directory.GetParent(String path) at Amazon.Runtime.StoredProfileAWSCredentials.DetermineCredentialsFilePath(String profilesLocation) at Amazon.Runtime.StoredProfileAWSCredentials..ctor(String profileName, String profilesLocation) at Amazon.Runtime.FallbackCredentialsFactory.<Reset>b__2() at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous) Exception 3 of 4: System.InvalidOperationException: The environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY were not set with AWS credentials. at Amazon.Runtime.EnvironmentVariablesAWSCredentials..ctor() at Amazon.Runtime.FallbackCredentialsFactory.<Reset>b__3() at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous) Exception 4 of 4: Amazon.Runtime.AmazonServiceException: Unable to reach credentials server at Amazon.Runtime.InstanceProfileAWSCredentials.GetContents(Uri uri) at Amazon.Runtime.InstanceProfileAWSCredentials.<GetAvailableRoles>d__0.MoveNext() at Amazon.Runtime.InstanceProfileAWSCredentials.GetFirstRole() at Amazon.Runtime.FallbackCredentialsFactory.<Reset>b__4() at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous) at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous) at Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient..ctor() at CellicaAwsSnsService..ctor() at Service..ctor() 

在可以从Web服务应用程序访问此路径的任何路径上创建凭证文件。例如。 C:\ awsfile \ credentials但请记住不要给这个文件任何扩展名文件应包含以下数据。

 [default] aws_access_key_id=[your_access_key] aws_secret_access_key=[your_secret_key] 

在此之后,您需要在Web.config文件中的appsetting标记中设置路径:

     

在AWS Explorer for Visual Studio中,您可以创建在AWS上为您提供不同权限的用户配置文件,然后您可以选择要在AWS Explorer中使用的配置文件。 这些配置文件仅适用于您的Windows用户帐户,如果其他人使用您的计算机,则他们必须创建自己的配置文件。 您在用户帐户下运行的任何软件也可以使用这些配置文件。

如果您未将应用程序配置为使用特定配置文件,则它将使用default配置文件。

出现此问题的原因是IIS在与您登录的用户帐户不同的用户帐户下运行,因此无权访问您的AWS配置文件。

有几种方法可以告诉您的应用程序在运行时使用哪个AWS配置文件(请参阅http://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/net-dg-config-creds。 HTML )。 开发人员最简单的选择是创建凭证文件并从web.config引用该文件。 例如,如果您创建一个名为C:\aws\credentials credentials的文件,则可以通过将此文件添加到您的web.config文件来告诉您的应用程序使用此凭证文件中的profile2。

   

凭证文件的内容应与此类似:

 [profile1] aws_access_key_id = {accessKey} aws_secret_access_key = {secretKey} [profile2] aws_access_key_id = {accessKey} aws_secret_access_key = {secretKey} 

要获取访问密钥和密钥,请访问AWS IAM控制台, url为https://console.aws.amazon.com/iam/home?region=us-east-1#/users,选择您希望应用程序使用的用户运行方式,然后单击“安全凭据”选项卡,然后单击“创建访问密钥”按钮。