Closed kron0s19 closed 1 year ago
Hi, I think that you are enabling some ECS specific path in the AWS SDK by adding the AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
variable (see: https://docs.aws.amazon.com/sdkref/latest/guide/feature-container-credentials.html).
Did you add a proper instance profile to your EC2 instance?
As it turns out, yes, the AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
was creating an issue.
I fixed it by actually settings the credentials by instantiating InstanceProfileAWSCredentials
AWSCredentials? credentials = IsAWS() ? new InstanceProfileAWSCredentials() : null;
configurationManager.AddSecretsManager(credentials, Region, options =>
{
var prefixes = new[] { $"{environmentName}_{applicationName}", applicationName };
options.SecretFilter = entry => prefixes.Any(prefix => entry.Name.StartsWith(prefix));
options.KeyGenerator = (_, s) => FormatKey(s, environmentName, applicationName);
options.PollingInterval = PollingInterval;
});
I have a legacy app running on a EC2 instance (NOT using ECS or EKS) , which is running on docker-compose with an nginx proxy.
If I run the app locally, It runs properly without issues.
Im pulling the secrets using that library with this code:
I added an IAM Role to the EC2 instance, and that role has SecretsManagerReadWrite permissions.
Using the cli on the instance, I can do:
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/MyRoleName And get a proper response
When we first ran the app, we WERE getting the following exception:
I updated the docker-compose adding 2 env variables (AWS_REGION and AWS_CONTAINER_CREDENTIALS_RELATIVE_URI). And it started working (no idea why).
This is the docker-compose
However, after updating the docker image and 'docker-compose up -d', it started failing again, but now with a different exception:
From the call stack, I can see that it is calling ECSTaskCredentials.GenerateNewCredentials(), but this is not running on ECS
Any help provided would be greatly appreciated beyond measure.