Amazon Secret Manager Helper
The AmazonSecretsManagerProvider Library provides methods for securely managing and retrieving secrets from AWS Secrets Manager. It allows applications to dynamically fetch credentials, API keys, and other sensitive information without hardcoding them.
Library: ADS.AmazonSecretManager.Helper
Service: AmazonSecretsManagerProvider
Methods
1. CreateClientByRegion
Signature: void CreateClientByRegion(string region);
Description:
- Initializes an AWS Secrets Manager client using the specified AWS region.
- This method is used when AWS credentials are managed via environment variables or IAM roles.
Parameters:
- region (string) – The AWS region where the Secrets Manager service is located (e.g., us-east-1).
2. CreateClientByKeys
Signature: void CreateClientByKeys(string region, string accessKeyId, string secretAccessKey);
Description:
- Initializes an AWS Secrets Manager client using explicit AWS credentials.
- This method is useful when accessing AWS from an environment where IAM roles are not available.
Parameters:
- region (string) – The AWS region where the Secrets Manager service is located.
- accessKeyId (string) – The AWS Access Key ID.
- secretAccessKey (string) – The AWS Secret Access Key.
3. GetSecretValue
Signature: Task<string> GetSecretValue(string secretName);
Description:
- Retrieves the secret value stored in AWS Secrets Manager.
- Returns the plaintext version of the secret as a string.
- This method is asynchronous and should be awaited.
Parameters:
- secretName (string) – The name of the secret stored in AWS Secrets Manager.
Returns: Task<string> – The value of the retrieved secret.
Example Usage
Creating a Client and Retrieving a Secret