Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does an EC2 instance access the Aws Secrets Manager

I have a .Net Core application that runs on an EC2 instance. I am looking this application to get the secrets I have stored on the Secrets Manager.

I have created a IAM Role that allows the Ec2 instance to access the secrets manager. However this is where I am stuck I don't know how to make use of that in my application nor can I find any tutorials online. Could some one explain how my application should access this the instance profile so I can retrieve the from secrets manager through their API.

Thank you.


1 Answers

You don't need to access the instance profile, the SDK does that for you. You just need to create a new instance of the client, and then use it.

var client = new Amazon.SecretsManager.AmazonSecretsManagerClient(Amazon.RegionEndpoint.USEast1);
var response = await client.GetSecretValueAsync(new Amazon.SecretsManager.Model.GetSecretValueRequest
            {
                SecretId = "mySecretIdOrArn"
            });

var secretString = response.SecretString;
like image 54
Jason Wadsworth Avatar answered Oct 26 '25 11:10

Jason Wadsworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!