Manage and Rotate Secrets with AWS Secrets Manager
Store, retrieve, and configure automatic rotation of secrets using AWS Secrets Manager for database credentials, API keys, and other sensitive data.
Prerequisites
- -AWS CLI v2 installed and configured
- -IAM permissions for Secrets Manager operations
Steps
Create a new secret
Store a new secret value in Secrets Manager with a descriptive name and optional tags for organization.
Avoid putting secrets directly in shell history. Use --secret-string file://secret.json to read from a file instead.
Retrieve a secret value
Fetch the current secret value and parse specific fields from the JSON payload.
Use --version-stage AWSPREVIOUS to retrieve the previous version of the secret, useful for verifying rotation worked correctly.
Enable automatic rotation
Configure a Lambda rotation function to automatically rotate the secret on a schedule.
AWS provides pre-built rotation Lambda functions for RDS, Redshift, and DocumentDB. Use the Serverless Application Repository to deploy them.
Trigger an immediate rotation
Manually trigger a rotation cycle to test the rotation function or rotate a potentially compromised credential immediately.
Rotation temporarily creates a new version staged as AWSPENDING. Ensure your application can handle brief credential transitions during the rotation window.
List secret versions and stages
Inspect the version history and staging labels to understand the current state of the secret and verify rotation completed successfully.
Full Script
FAQ
Discussion
Loading comments...