Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Create AWS Secrets Manager secrets in AWS CloudFormation

Focus mode
Create AWS Secrets Manager secrets in AWS CloudFormation - AWS Secrets Manager

You can create secrets in a CloudFormation stack by using the AWS::SecretsManager::Secret resource in a CloudFormation template, as shown in Create a secret.

To create an admin secret for Amazon RDS or Aurora, we recommend you use ManageMasterUserPassword in AWS::RDS::DBCluster. Then Amazon RDS creates the secret and manages rotation for you. For more information, see Managed rotation.

For Amazon Redshift and Amazon DocumentDB credentials, first create a secret with a password generated by Secrets Manager, and then use a dynamic reference to retrieve the username and password from the secret to use as credentials for a new database. Next, use the AWS::SecretsManager::SecretTargetAttachment resource to add details about the database to the secret that Secrets Manager needs to rotate the secret. Finally, to turn on automatic rotation, use the AWS::SecretsManager::RotationSchedule resource and provide a rotation function and a schedule. See the following examples:

To attach a resource policy to your secret, use the AWS::SecretsManager::ResourcePolicy resource.

For information about creating resources with AWS CloudFormation, see Learn template basics in the AWS CloudFormation User Guide. You can also use the AWS Cloud Development Kit (AWS CDK). For more information, see AWS Secrets Manager Construct Library.

How Secrets Manager uses AWS CloudFormation

When you use the console to turn on rotation, Secrets Manager uses AWS CloudFormation to create resources for rotation. If you create a new rotation function during that process, AWS CloudFormation creates an AWS::Serverless::Function based on the appropriate Rotation function templates. Then AWS CloudFormation sets the RotationSchedule, which sets the rotation function and rotation rules for the secret. You can view the AWS CloudFormation stack by choosing View stack in the banner after you turn on automatic rotation.

For information about turning on automatic rotation, see Rotate AWS Secrets Manager secrets.

On this page

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.