2 Answers
- Newest
- Most votes
- Most comments
2
You will need a Lambda function for Secret rotation
# Define your Secret
my_secret = secretsmanager.Secret(self, "MySecret",
secret_name="MySecret",
generate_secret_string=secretsmanager.SecretStringGenerator())
# Create a Lambda function for rotation
rotation_lambda = lambda_.Function(self, "RotationLambda",
runtime=lambda_.Runtime.PYTHON_3_8,
handler="rotation_function.handler",
code=lambda_.Code.from_asset("path_to_your_lambda_code"))
# Grant Lambda permissions to read and update the secret
my_secret.grant_read(rotation_lambda)
my_secret.grant_write(rotation_lambda)
# Define rotation schedule
rotation_schedule = secretsmanager.RotationSchedule(
self, "RotationSchedule",
secret=my_secret,
rotation_lambda=rotation_lambda,
rotation_schedule=core.Duration.days(30)
)
# Enable rotation for the secret
my_secret.add_rotation_schedule("RotationSchedule", rotation_schedule)
Lambda examples are here: https://github.com/aws-samples/aws-secrets-manager-rotation-lambdas/tree/master
1
The cdk-nag error resulted from a bug
The secrets rotation was set but non-compliant even if rotation is configured. I was working under version v2.116 for aws-cdk-lib, and updating to 2.129.0 resolved the issue SMG4.
answered a year ago
Relevant content
- asked 2 years ago
- asked a year ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago