AmazonServiceException:无法找到凭据

AmazonServiceException: Unable to find credentials

仅在我的生产环境中将 sdk 核心更新到版本 3.3.10.2 后,我开始 运行 出现此错误。我正在负载均衡器中的 4 个 ec2 实例上部署 .net api。所有 Windows 服务器 2012 R2。

奇怪的是,真正让我发疯的部分是,如果我在 VS 2015 中调试它,应用程序运行没有问题,如果我将应用程序发布到我的本地 IIS,它运行正常。当我在我们的任何生产机器上部署应用程序时发生错误。

我正在使用:

<add key="AWSProfileName" value="{profile name}" />
<add key="AWSProfilesLocation" value="{file location}" />

连同其中包含适当数据的凭据文件。

在任何人询问之前,此应用程序在过去 6 个月中一直在使用 AWS s3 的这种配置中工作,并且关于凭据或类似内容的错误为零。

更糟糕的是,即使我尝试将 aws sdk 降级回任何其他版本,错误仍然存​​在。我完全不知道错误从何而来或如何解决。请帮忙

这是堆栈跟踪:

[AmazonServiceException: Unable to find credentials

Exception 1 of 4:
System.TypeInitializationException: The type initializer for 'Amazon.Runtime.CredentialManagement.AWSCredentialsFactory' threw an exception. ---> Amazon.Runtime.AmazonClientException: The encrypted store is not available on this platform.
   at Amazon.Util.Internal.SettingsManager.EnsureAvailable()
   at Amazon.Runtime.CredentialManagement.SAMLEndpointManager..ctor()
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory..cctor()
   --- End of inner exception stack trace ---
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory.IsCallbackRequired(Nullable`1 profileType)
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory.GetAWSCredentials(String profileName, ICredentialProfileSource profileSource, CredentialProfileOptions options, RegionEndpoint stsRegion, Boolean nonCallbackOnly)
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory.GetAWSCredentials(CredentialProfile profile, ICredentialProfileSource profileSource, Boolean nonCallbackOnly)
   at Amazon.Runtime.AppConfigAWSCredentials..ctor()
   at Amazon.Runtime.FallbackCredentialsFactory.<>c.<Reset>b__8_0()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 2 of 4:
Amazon.Runtime.AmazonClientException: Unable to find a default profile in CredentialProfileStoreChain.
   at Amazon.Runtime.FallbackCredentialsFactory.GetAWSCredentials(ICredentialProfileSource source, String defaultProfileName)
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 3 of 4:
System.InvalidOperationException: The environment variables AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN were not set with AWS credentials.
   at Amazon.Runtime.EnvironmentVariablesAWSCredentials.FetchCredentials()
   at Amazon.Runtime.FallbackCredentialsFactory.<>c.<Reset>b__8_2()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 4 of 4:
Amazon.Runtime.AmazonServiceException: Unable to reach credentials server
   at Amazon.Runtime.URIBasedRefreshingCredentialHelper.GetContents(Uri uri)
   at Amazon.Runtime.InstanceProfileAWSCredentials.<GetAvailableRoles>d__10.MoveNext()
   at Amazon.Runtime.InstanceProfileAWSCredentials.GetFirstRole()
   at Amazon.Runtime.FallbackCredentialsFactory.ECSEC2CredentialsWrapper()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

]
   Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous) +718
   Amazon.S3.AmazonS3Client..ctor(RegionEndpoint region) +59
   MGX_2.Models.S3Connection.Read() +83
   MGX_2.Models.S3Connection.ReadToString(String k) +43
   MGX_2.MgxConfig.Update() +118
   MGX_2.MgxConfig.Init() +11
   MGX_2.WebApiApplication.Application_Start() +302

[HttpException (0x80004005): Unable to find credentials

Exception 1 of 4:
System.TypeInitializationException: The type initializer for 'Amazon.Runtime.CredentialManagement.AWSCredentialsFactory' threw an exception. ---> Amazon.Runtime.AmazonClientException: The encrypted store is not available on this platform.
   at Amazon.Util.Internal.SettingsManager.EnsureAvailable()
   at Amazon.Runtime.CredentialManagement.SAMLEndpointManager..ctor()
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory..cctor()
   --- End of inner exception stack trace ---
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory.IsCallbackRequired(Nullable`1 profileType)
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory.GetAWSCredentials(String profileName, ICredentialProfileSource profileSource, CredentialProfileOptions options, RegionEndpoint stsRegion, Boolean nonCallbackOnly)
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory.GetAWSCredentials(CredentialProfile profile, ICredentialProfileSource profileSource, Boolean nonCallbackOnly)
   at Amazon.Runtime.AppConfigAWSCredentials..ctor()
   at Amazon.Runtime.FallbackCredentialsFactory.<>c.<Reset>b__8_0()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 2 of 4:
Amazon.Runtime.AmazonClientException: Unable to find a default profile in CredentialProfileStoreChain.
   at Amazon.Runtime.FallbackCredentialsFactory.GetAWSCredentials(ICredentialProfileSource source, String defaultProfileName)
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 3 of 4:
System.InvalidOperationException: The environment variables AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN were not set with AWS credentials.
   at Amazon.Runtime.EnvironmentVariablesAWSCredentials.FetchCredentials()
   at Amazon.Runtime.FallbackCredentialsFactory.<>c.<Reset>b__8_2()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 4 of 4:
Amazon.Runtime.AmazonServiceException: Unable to reach credentials server
   at Amazon.Runtime.URIBasedRefreshingCredentialHelper.GetContents(Uri uri)
   at Amazon.Runtime.InstanceProfileAWSCredentials.<GetAvailableRoles>d__10.MoveNext()
   at Amazon.Runtime.InstanceProfileAWSCredentials.GetFirstRole()
   at Amazon.Runtime.FallbackCredentialsFactory.ECSEC2CredentialsWrapper()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +544
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +186
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +402
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +343

[HttpException (0x80004005): Unable to find credentials

Exception 1 of 4:
System.TypeInitializationException: The type initializer for 'Amazon.Runtime.CredentialManagement.AWSCredentialsFactory' threw an exception. ---> Amazon.Runtime.AmazonClientException: The encrypted store is not available on this platform.
   at Amazon.Util.Internal.SettingsManager.EnsureAvailable()
   at Amazon.Runtime.CredentialManagement.SAMLEndpointManager..ctor()
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory..cctor()
   --- End of inner exception stack trace ---
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory.IsCallbackRequired(Nullable`1 profileType)
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory.GetAWSCredentials(String profileName, ICredentialProfileSource profileSource, CredentialProfileOptions options, RegionEndpoint stsRegion, Boolean nonCallbackOnly)
   at Amazon.Runtime.CredentialManagement.AWSCredentialsFactory.GetAWSCredentials(CredentialProfile profile, ICredentialProfileSource profileSource, Boolean nonCallbackOnly)
   at Amazon.Runtime.AppConfigAWSCredentials..ctor()
   at Amazon.Runtime.FallbackCredentialsFactory.<>c.<Reset>b__8_0()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 2 of 4:
Amazon.Runtime.AmazonClientException: Unable to find a default profile in CredentialProfileStoreChain.
   at Amazon.Runtime.FallbackCredentialsFactory.GetAWSCredentials(ICredentialProfileSource source, String defaultProfileName)
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 3 of 4:
System.InvalidOperationException: The environment variables AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN were not set with AWS credentials.
   at Amazon.Runtime.EnvironmentVariablesAWSCredentials.FetchCredentials()
   at Amazon.Runtime.FallbackCredentialsFactory.<>c.<Reset>b__8_2()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 4 of 4:
Amazon.Runtime.AmazonServiceException: Unable to reach credentials server
   at Amazon.Runtime.URIBasedRefreshingCredentialHelper.GetContents(Uri uri)
   at Amazon.Runtime.InstanceProfileAWSCredentials.<GetAvailableRoles>d__10.MoveNext()
   at Amazon.Runtime.InstanceProfileAWSCredentials.GetFirstRole()
   at Amazon.Runtime.FallbackCredentialsFactory.ECSEC2CredentialsWrapper()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +712

所以这显然是 AWSSDK 中的一个错误。 3.3.10.3 更新后问题不复存在。感谢众多回复!