Storing Credentials in Secrets Manager
Store and rotate database and API secrets safely, never in code.
Storing Credentials in Secrets Manager is a free AWS Security Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Hardcoded Secret Problem
Database passwords and API keys hardcoded in code or config files are a top breach cause. They leak through repos, logs, and backups.
AWS Secrets Manager stores secrets securely, controls access with IAM, and can rotate them automatically, so secrets never live in your code.
What Secrets Manager Does
Secrets Manager stores, encrypts, retrieves, and rotates secrets such as database credentials and API keys.
- Secrets are encrypted at rest with KMS.
- Apps fetch them at runtime via an API call instead of embedding them.
Encryption and Access Control
Each secret is encrypted with a KMS key and guarded by IAM and an optional resource-based policy.
You grant only the specific roles that need a secret access to it, and every retrieval is logged in CloudTrail, giving full accountability.
Automatic Rotation
The standout feature is automatic rotation.
- A Lambda function changes the secret on a schedule and updates the store.
- Built-in rotation supports RDS and other databases.
Rotation limits the damage window if a credential is ever exposed.
How Rotation Works
For databases, rotation typically uses two sets of credentials or an alternating-user strategy so applications never see an invalid password during the change.
The Lambda creates a new secret value, tests it, then promotes it, all without downtime when configured correctly.
Retrieving Secrets at Runtime
Applications call GetSecretValue to fetch a secret when needed, often caching it briefly.
Because the app holds an IAM role, no static credentials are needed to retrieve the secret, completing the chain of removing long-term keys from code.
aws secretsmanager get-secret-value \
--secret-id prod/db/credentials \
--query SecretStringSecrets Manager vs Parameter Store
SSM Parameter Store also stores configuration and secrets (SecureString) and is free for standard parameters.
- Choose Secrets Manager for built-in automatic rotation and cross-account secret sharing.
- Choose Parameter Store for simpler, cost-free config without rotation.
Cross-Account and Cross-Region
Secrets Manager supports a resource policy to share a secret with another account and can replicate secrets to other regions.
This serves multi-region apps and disaster recovery, keeping a consistent secret available where the workload runs.
Auditing and Monitoring
Monitor secret usage with CloudTrail (who retrieved or rotated a secret) and detect anomalies.
For example, GuardDuty can flag unusual access patterns, and Config rules can check that rotation is enabled, keeping secret hygiene measurable.
Integration with Other Services
Many AWS services consume Secrets Manager secrets natively.
- RDS and Redshift can store and manage their master credentials there.
- ECS, Lambda, and CodeBuild can inject secrets at runtime.
This means workloads receive credentials securely without your code ever embedding or fetching them manually.
Best Practices
To use secrets safely:
- Never hardcode secrets; fetch from Secrets Manager.
- Enable rotation and use a dedicated KMS key.
- Grant least-privilege access per secret and audit retrievals.
Quick Check
Choose the right service.
Recap
You learned about Secrets Manager.
- It stores, encrypts (with KMS), and rotates secrets automatically.
- Apps fetch secrets at runtime via IAM-controlled API calls, never hardcoding them.
- Choose it over Parameter Store when you need rotation or cross-account sharing.
Frequently asked questions
Is the “Storing Credentials in Secrets Manager” lesson free?
Yes — the full text of “Storing Credentials in Secrets Manager” is free to read here on the web, and the AWS Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Security Academy course, upgrade to CoddyKit PRO.
What will I learn in “Storing Credentials in Secrets Manager”?
Store and rotate database and API secrets safely, never in code. You practise AWS Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Security Academy?
No prior experience is required. AWS Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Storing Credentials in Secrets Manager” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Security Academy lesson?
Yes. Every AWS Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Encrypting S3, EBS, and RDS at Rest
- Enforcing Default Encryption Everywhere
- TLS Certificates with AWS Certificate Manager
- Storing Credentials in Secrets Manager