aws-cdk-lib.aws_secretsmanager.SecretStringGenerator

interface SecretStringGenerator

LanguageType name
.NETAmazon.CDK.AWS.SecretsManager.SecretStringGenerator
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awssecretsmanager#SecretStringGenerator
Javasoftware.amazon.awscdk.services.secretsmanager.SecretStringGenerator
Pythonaws_cdk.aws_secretsmanager.SecretStringGenerator
TypeScript (source)aws-cdk-lib » aws_secretsmanager » SecretStringGenerator

Configuration to generate secrets such as passwords automatically.

Example

declare const vpc: ec2.IVpc;

const instance1 = new rds.DatabaseInstance(this, "PostgresInstance1", {
  engine: rds.DatabaseInstanceEngine.POSTGRES,
  // Generate the secret with admin username `postgres` and random password
  credentials: rds.Credentials.fromGeneratedSecret('postgres'),
  vpc
});
// Templated secret with username and password fields
const templatedSecret = new secretsmanager.Secret(this, 'TemplatedSecret', {
  generateSecretString: {
    secretStringTemplate: JSON.stringify({ username: 'postgres' }),
    generateStringKey: 'password',
    excludeCharacters: '/@"',
  },
});
// Using the templated secret as credentials
const instance2 = new rds.DatabaseInstance(this, "PostgresInstance2", {
  engine: rds.DatabaseInstanceEngine.POSTGRES,
  credentials: {
    username: templatedSecret.secretValueFromJson('username').toString(),
    password: templatedSecret.secretValueFromJson('password')
  },
  vpc
});

Properties

NameTypeDescription
excludeCharacters?stringA string that includes characters that shouldn't be included in the generated password.
excludeLowercase?booleanSpecifies that the generated password shouldn't include lowercase letters.
excludeNumbers?booleanSpecifies that the generated password shouldn't include digits.
excludePunctuation?booleanSpecifies that the generated password shouldn't include punctuation characters.
excludeUppercase?booleanSpecifies that the generated password shouldn't include uppercase letters.
generateStringKey?stringThe JSON key name that's used to add the generated password to the JSON structure specified by the secretStringTemplate parameter.
includeSpace?booleanSpecifies that the generated password can include the space character.
passwordLength?numberThe desired length of the generated password.
requireEachIncludedType?booleanSpecifies whether the generated password must include at least one of every allowed character type.
secretStringTemplate?stringA properly structured JSON string that the generated password can be added to.

excludeCharacters?

Type: string (optional, default: no exclusions)

A string that includes characters that shouldn't be included in the generated password.

The string can be a minimum of 0 and a maximum of 4096 characters long.


excludeLowercase?

Type: boolean (optional, default: false)

Specifies that the generated password shouldn't include lowercase letters.


excludeNumbers?

Type: boolean (optional, default: false)

Specifies that the generated password shouldn't include digits.


excludePunctuation?

Type: boolean (optional, default: false)

Specifies that the generated password shouldn't include punctuation characters.


excludeUppercase?

Type: boolean (optional, default: false)

Specifies that the generated password shouldn't include uppercase letters.


generateStringKey?

Type: string (optional)

The JSON key name that's used to add the generated password to the JSON structure specified by the secretStringTemplate parameter.

If you specify generateStringKey then secretStringTemplate must be also be specified.


includeSpace?

Type: boolean (optional, default: false)

Specifies that the generated password can include the space character.


passwordLength?

Type: number (optional, default: 32)

The desired length of the generated password.


requireEachIncludedType?

Type: boolean (optional, default: true)

Specifies whether the generated password must include at least one of every allowed character type.


secretStringTemplate?

Type: string (optional)

A properly structured JSON string that the generated password can be added to.

The generateStringKey is combined with the generated random string and inserted into the JSON structure that's specified by this parameter. The merged JSON string is returned as the completed SecretString of the secret. If you specify secretStringTemplate then generateStringKey must be also be specified.