AmazonServiceException: Unable to find credentials

2019-07-23 21:05发布

I started running into this error after updating the sdk core to version 3.3.10.2 on my production environment only. I am deploying a .net api on 4 ec2 instances in a load balancer. All Windows Server 2012 R2.

The odd part, and really the part that is driving me nuts, is the application runs without issue if I debug it in VS 2015 and it runs fine if I publish the application to my local IIS. When I deploy the application on any of our production machines the error occurs.

I am using:

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

along with a credential file with the appropriate data in it.

Before anyone asks, this application has worked for the last 6 months in this very configuration with AWS s3 and zero errors regarding credentials or anything like this.

What's worse is that even when I try to downgrade the aws sdk back to any other version, the error persists. I have absolutely no idea where the error came from or how to fix it. Please help.

Here is the stack trace:

[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

1条回答
淡お忘
2楼-- · 2019-07-23 21:39

So this was apparently an error in the AWSSDK. After the 3.3.10.3 update the problem no longer exists. Thanks for the numerous responses!

查看更多
登录 后发表回答