AWS Secrets Manager stores credentials so that you can replace a hard-coded password with an API call that returns it. Because you chose Managed in AWS Secrets Manager when you created rdspg-dev-db, RDS created the secret for you, keeps it in sync with the database, and rotates the password automatically.
| Self managed password | Managed in Secrets Manager | |
|---|---|---|
| Who creates the password | You | RDS |
| Where it is kept | Wherever you put it (config file, environment variable, wiki…) | A secret named rds!db-<id>, encrypted with AWS KMS |
| Rotation | Manual | Automatic, every 7 days by default |
| How the application gets it | Copy it into the configuration | GetSecretValue, allowed by IAM |
Open the AWS Secrets Manager console:
rds!db-<id> was created by RDS. The name is not something you choose.rdspg-dev-db.
Choose the secret:
aws/secretsmanager.
In the Rotation tab:

Because the password changes every week, an application must not read it once and keep it forever. In chapter 3 the code reads the secret when it opens a new connection, with a short cache, so a rotation does not break it.
In the Session Manager terminal (as ec2-user), find the ARN of the secret from the DB instance, then read the secret. The command prints only the user name:
SECRET_ARN=$(aws rds describe-db-instances --db-instance-identifier rdspg-dev-db \
--query 'DBInstances[0].MasterUserSecret.SecretArn' --output text)
aws secretsmanager get-secret-value --secret-id "$SECRET_ARN" --query SecretString --output text \
| jq '{username, password: "(hidden)"}'
aws secretsmanager list-secrets 2>&1 | cut -c1-110
username (postgres) and password.list-secrets fails with AccessDeniedException: the role can read only the RDS-managed secrets, nothing else.
MasterUserSecret.SecretArn is the reliable way to find the secret: the name rds!db-<id> is generated by RDS and changes if you recreate the DB instance. Never print the password in logs or terminal output.