You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Applications need secrets — database passwords, API keys, OAuth tokens, encryption keys. Hardcoding these values in source code or configuration files is a serious security risk. AWS provides two services to manage secrets securely: AWS Secrets Manager and AWS Systems Manager Parameter Store.
Hardcoding secrets leads to multiple issues:
Both Secrets Manager and Parameter Store solve these problems by externalising secrets from your application code.
Secrets Manager is a purpose-built service for storing, retrieving, and automatically rotating secrets.
| Feature | Description |
|---|---|
| Encryption | All secrets are encrypted at rest using KMS |
| Automatic rotation | Built-in rotation for RDS, Redshift, and DocumentDB; custom Lambda rotation for others |
| Fine-grained access | IAM policies and resource-based policies control who can access each secret |
| Versioning | Secrets are versioned — you can access current and previous values |
| Cross-account access | Resource-based policies allow sharing secrets across AWS accounts |
| Audit | CloudTrail logs every API call — you know who accessed what and when |
aws secretsmanager create-secret \
--name production/database/password \
--description "Production database master password" \
--secret-string '{"username":"admin","password":"S3cur3P@ssw0rd!"}'
aws secretsmanager get-secret-value \
--secret-id production/database/password
In application code (Node.js example):
const { SecretsManagerClient, GetSecretValueCommand } = require('@aws-sdk/client-secrets-manager');
const client = new SecretsManagerClient({ region: 'eu-west-2' });
const response = await client.send(new GetSecretValueCommand({ SecretId: 'production/database/password' }));
const secret = JSON.parse(response.SecretString);
console.log(secret.username); // "admin"
Secrets Manager can automatically rotate secrets on a schedule (e.g., every 30 days). For RDS databases, the rotation is built-in — Secrets Manager:
For other secret types, you provide a custom Lambda function that handles the rotation logic.
aws secretsmanager rotate-secret \
--secret-id production/database/password \
--rotation-lambda-arn arn:aws:lambda:eu-west-2:123456789012:function:RotateMySecret \
--rotation-rules AutomaticallyAfterDays=30
Parameter Store is part of AWS Systems Manager and provides a hierarchical store for configuration data and secrets.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.