Credentials Class
Username and password combination.
Example
ts
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
});
Initializer
ts
new Credentials()
python
Credentials()
java
new Credentials()
csharp
new Credentials()
go
NewCredentials()
Properties
encryptionKeyIKeyencryption_keyIKeyencryptionKeyIKeyEncryptionKeyIKeyEncryptionKeyIKey= default master key#KMS encryption key to encrypt the generated secret.
excludeCharactersstringexclude_charactersstrexcludeCharactersStringExcludeCharactersstringExcludeCharacters*string= the DatabaseSecret default exclu…#The characters to exclude from the generated password.
Only used if password has not been set.
default
Default: the DatabaseSecret default exclude character set (" %+~`#$&*()|[]{}:;<>?!'/@\"\\")
passwordSecretValuepasswordSecretValuepasswordSecretValuePasswordSecretValuePasswordSecretValue= a Secrets Manager generated pass…#Password.
Do not put passwords in your CDK code directly.
default
Default: a Secrets Manager generated password
replicaRegionsReplicaRegion[]replica_regionstyping.List[ReplicaRegion]replicaRegionsList<ReplicaRegion>ReplicaRegionsReplicaRegion[]ReplicaRegions*[]ReplicaRegion= Secret is not replicated#A list of regions where to replicate the generated secret.
Secret used to instantiate this Login.
secretNamestringsecret_namestrsecretNameStringSecretNamestringSecretName*string= A name is generated by CloudForm…#The name to use for the Secret if a new Secret is to be generated in SecretsManager for these Credentials.
default
Default: A name is generated by CloudFormation.
Username.
usernameAsStringbooleanusername_as_stringboolusernameAsStringBooleanUsernameAsStringboolUsernameAsString*bool= false#Whether the username should be referenced as a string and not as a dynamic reference to the username in the secret.
Methods
fromGeneratedSecret(username: string, options?: CredentialsBaseOptions): Credentials // chainable@staticmethod def from_generated_secret(username: str, options: typing.Optional[CredentialsBaseOptions] = None) -> Credentialspublic static Credentials fromGeneratedSecret(String username, CredentialsBaseOptions options)public static Credentials FromGeneratedSecret(string username, CredentialsBaseOptions? options = null)func FromGeneratedSecret(Username *string, Options CredentialsBaseOptions) Credentialsstatic#Creates Credentials with a password generated and stored in Secrets Manager.
fromPassword(username: string, password: SecretValue): Credentials // chainable@staticmethod def from_password(username: str, password: SecretValue) -> Credentialspublic static Credentials fromPassword(String username, SecretValue password)public static Credentials FromPassword(string username, SecretValue password)func FromPassword(Username *string, Password SecretValue) Credentialsstatic#Creates Credentials from a password.
Do not put passwords in your CDK code directly.
fromSecret(secret: ISecret, username?: string): Credentials // chainable@staticmethod def from_secret(secret: ISecret, username: typing.Optional[str] = None) -> Credentialspublic static Credentials fromSecret(ISecret secret, String username)public static Credentials FromSecret(ISecret secret, string? username = null)func FromSecret(Secret ISecret, Username *string) Credentialsstatic#Creates Credentials from an existing Secrets Manager ``Secret`` (or ``DatabaseSecret``).
The Secret must be a JSON string with a username and password field:
{
...
"username": <required: username>,
"password": <required: password>,
}
2 parameters
Parameters
secretsecretsecretsecretSecret— The secret where the credentials are stored.usernameusernameusernameusernameUsername— The username defined in the secret.
fromUsername(username: string, options?: CredentialsFromUsernameOptions): Credentials // chainable@staticmethod def from_username(username: str, options: typing.Optional[CredentialsFromUsernameOptions] = None) -> Credentialspublic static Credentials fromUsername(String username, CredentialsFromUsernameOptions options)public static Credentials FromUsername(string username, CredentialsFromUsernameOptions? options = null)func FromUsername(Username *string, Options CredentialsFromUsernameOptions) Credentialsstatic#Creates Credentials for the given username, and optional password and key.
If no password is provided, one will be generated and stored in Secrets Manager.