-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathdatabase-secret.ts
39 lines (36 loc) · 1003 Bytes
/
database-secret.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as kms from 'aws-cdk-lib/aws-kms';
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
import { Construct } from 'constructs';
/**
* Construction properties for a DatabaseSecret.
*/
export interface DatabaseSecretProps {
/**
* The username.
*/
readonly username: string;
/**
* The KMS key to use to encrypt the secret.
*
* @default default master key
*/
readonly encryptionKey?: kms.IKey;
}
/**
* A database secret.
*
* @resource AWS::SecretsManager::Secret
*/
export class DatabaseSecret extends secretsmanager.Secret {
constructor(scope: Construct, id: string, props: DatabaseSecretProps) {
super(scope, id, {
encryptionKey: props.encryptionKey,
generateSecretString: {
passwordLength: 30, // Redshift password could be up to 64 characters
secretStringTemplate: JSON.stringify({ username: props.username }),
generateStringKey: 'password',
excludeCharacters: '"@/\\\ \'',
},
});
}
}