Skip to content

Commit 32dfa6e

Browse files
docs: explain SnapshotCredentials (#20431)
fixes #20388 I'm interested in why `DatabaseClusterFromSnapshot` generates an `admin` username unlike the other snapshot constructs, I'm unfamiliar with why it's be okay to generate a username for that but not an instance or serverless cluster ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent f9552c0 commit 32dfa6e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/@aws-cdk/aws-rds/README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ const rule = instance.onEvent('InstanceEvent', { target: new targets.LambdaFunct
185185

186186
## Login credentials
187187

188-
By default, database instances and clusters will have `admin` user with an auto-generated password.
188+
By default, database instances and clusters (with the exception of `DatabaseInstanceFromSnapshot` and `ServerlessClusterFromSnapshot`) will have `admin` user with an auto-generated password.
189189
An alternative username (and password) may be specified for the admin user instead of the default.
190190

191191
The following examples use a `DatabaseInstance`, but the same usage is applicable to `DatabaseCluster`.
@@ -232,6 +232,27 @@ new rds.DatabaseInstance(this, 'InstanceWithCustomizedSecret', {
232232
});
233233
```
234234

235+
### Snapshot credentials
236+
237+
As noted above, Databases created with `DatabaseInstanceFromSnapshot` or `ServerlessClusterFromSnapshot` will not create user and auto-generated password by default because it's not possible to change the master username for a snapshot. Instead, they will use the existing username and password from the snapshot. You can still generate a new password - to generate a secret similarly to the other constructs, pass in credentials with `fromGeneratedSecret()` or `fromGeneratedPassword()`.
238+
239+
```ts
240+
declare const vpc: ec2.Vpc;
241+
const engine = rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_12_3 });
242+
const myKey = new kms.Key(this, 'MyKey');
243+
244+
new rds.DatabaseInstanceFromSnapshot(this, 'InstanceFromSnapshotWithCustomizedSecret', {
245+
engine,
246+
vpc,
247+
snapshotIdentifier: 'mySnapshot',
248+
credentials: rds.SnapshotCredentials.fromGeneratedSecret('username', {
249+
encryptionKey: myKey,
250+
excludeCharacters: '!&*^#@()',
251+
replicaRegions: [{ region: 'eu-west-1' }, { region: 'eu-west-2' }],
252+
}),
253+
});
254+
```
255+
235256
## Connecting
236257

237258
To control who can access the cluster or instance, use the `.connections` attribute. RDS databases have

0 commit comments

Comments
 (0)