I am using SecretsManager to store my Access & Secret Key. Below is the code I am using to fetch the secrets from AWS SecretsManager.
Constants constants = new Constants();
IAmazonSecretsManager client = new AmazonSecretsManagerClient(constants.Region);
GetSecretValueRequest request = new GetSecretValueRequest
{
SecretId = Constants.secretName, VersionStage = Constants.VersionStage, // VersionStage defaults to AWSCURRENT if unspecified.
};
GetSecretValueResponse response;
response = await client.GetSecretValueAsync(request);
NOTE :-
- My code is working perfectly fine when I am running my code on local machine.
- I am using same code in console application it works fine there as well. I am not sure why I am getting error while I host my application to IIS
- I have properly configure the AWS Creds using
aws configure
command. I dont think this would be the issue.
The moment I host my code to IIS server (In AWS EC2 machine).
It started giving me error on
this line -- response = await client.GetSecretValueAsync(request);
Error :-
Amazon.Runtime.AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service.
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync()
at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
at UtilityProject.RetrieveSecretAndAccessKeys.GetSecret()
Application I am using is :- DotNet Core 5.0