【问题标题】:Amazon.Runtime.AmazonServiceException: Unable to find credentialsAmazon.Runtime.AmazonServiceException:找不到凭证
【发布时间】:2020-01-17 18:19:51
【问题描述】:

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

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

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()

【问题讨论】:

  • 嗨,您是否检查过您的网络服务器是否可以访问网络服务 URL?有时防火墙会阻止它
  • 是的,我检查了它,它在本地 IIS 中也不起作用,当我将它发布到本地 IIS 时,给出了同样的错误。

标签: c# amazon-web-services


【解决方案1】:

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

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

之后需要在Web.config文件的appsetting标签中设置路径:

<appSettings>
<add key="AWSProfilesLocation" value="C:\awsfile\credentials" />
<add key="AWSRegion" value="us-east-1" />
</appSettings>

【讨论】:

  • 已批准 :) 将这些 cmets 分箱
【解决方案2】:

在 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 的文件,您可以通过将其添加到您的 web.config 文件中来告诉您的应用程序使用此凭据文件中的 profile2。

<configuration>

  <configSections>
    <section name="aws" type="Amazon.AWSSection, AWSSDK.Core" />
  </configSections>

  <aws 
    region="us-east-1" 
    profileName="profile2"
    profilesLocation="C:\aws\credentials" />

</configuration>

凭证文件的内容应该是这样的:

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

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

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

【讨论】:

    猜你喜欢
    • 2017-08-13
    • 2018-12-15
    • 2019-04-10
    • 2016-08-24
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-30
    相关资源
    最近更新 更多