Access AWS secret manager secret from outside AWS ecosystem/environment

0

Hi, I would like to know if it is possible to access a secret that I have configured in the secret manager from outside the AWS ecosystem, let's say locally or on a server that is outside.

I have given a policy to a group where I have created a user.

I am using .net 8.0 and this is a code that I am using it is a snippet code provided by aws.

 string secretName = "****";
 string region = "****";

 IAmazonSecretsManager client = new AmazonSecretsManagerClient(RegionEndpoint.GetBySystemName(region));

 GetSecretValueRequest request = new GetSecretValueRequest
 {
     SecretId = secretName
 };

 GetSecretValueResponse response;

 try
 {
     response = await client.GetSecretValueAsync(request);
 }
 catch (Exception e)
 {
     throw e;
 }

 string secret = response.SecretString;

It is failing with the following error:

"Unable to get IAM security credentials from EC2 Instance Metadata Service"

Thanks

Eneko
asked a month ago171 views
1 Answer
1

Hello,

To access AWS Secrets Manager from outside the AWS, such as from a local machine, you need to ensure proper AWS credentials are configured.

  1. Create AWS IAM user with the necessary permissions to access Secrets Manager.
  2. Configure credentials on your local machine using aws cli.
  3. Update .NET Code to Use Local AWS Credentials.

AWS policy that grants permission to access secrets to an IAM user

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "secretsmanager:GetSecretValue"
            ],
            "Resource": "arn:aws:secretsmanager:region:account-id:secret:secret-id"
        }
    ]
}
profile picture
EXPERT
answered a month ago
profile pictureAWS
EXPERT
reviewed a month ago