Using AWS Secret Manager to store credentials

AWS Secret Manager is an AWS service that stores and rotate application credentials, database credentials, and API keys and other secrets throughout their lifecycle. AWS Secret Manager is like Vault service that provides storage and rotates the important credentials. Here is an example Using CLI to create a Database secret using secret Manager. Create AWS Secret using CLI aws secretsmanager create-secret \ --name my-database-password \ --description "My database secret created with the CLI." \ --secret-string "\"password\":\"YourSecurePassword\"}" Below code retrieve secret from secret manager data "aws_secretmanager_secret_version" "my_secret" { secret_id = "my_secret_name" } following code fetch secret from Secret manager and insert in the resource config resource "aws_db_instance" "my_database" { # other DB configuration password = data.aws_secretmanager_secret_version.mysecret.secretstring }

Mar 12, 2025 - 22:22
 0
Using AWS Secret Manager to store credentials
AWS Secret Manager is an AWS service that stores and rotate application credentials, database credentials, and API keys and other secrets throughout their lifecycle.

AWS Secret Manager is like Vault service that provides storage and rotates the important credentials.

Here is an example Using CLI to create a Database secret using secret Manager.

Create AWS Secret using CLI

aws secretsmanager create-secret \
--name my-database-password \
--description "My database secret created with the CLI." \
--secret-string "\"password\":\"YourSecurePassword\"}"

Below code retrieve secret from secret manager

data "aws_secretmanager_secret_version" "my_secret" {
secret_id = "my_secret_name"
}

following code fetch secret from Secret manager and insert in the resource config

resource "aws_db_instance" "my_database" {
# other DB configuration
password = data.aws_secretmanager_secret_version.mysecret.secretstring
}