forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rds): clusters created from snapshots generate incorrect passwords (
aws#20504) Deprecate `credentials` and explain how it is broken. Replace it with `snapshotCredentials` that offer the expected behavior. Fixes aws#20434 Closes aws#20473 ---- ### All Submissions: * [x] 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*
- Loading branch information
Showing
18 changed files
with
6,075 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...napshot/asset.1e025324752b3133dc230c4b8b8752f666b63c09cd4aa605ec2b322cc40def2e/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { IsCompleteRequest, IsCompleteResponse, OnEventRequest, OnEventResponse } from '@aws-cdk/custom-resources/lib/provider-framework/types'; | ||
export declare function onEventHandler(event: OnEventRequest): Promise<OnEventResponse>; | ||
export declare function isCompleteHandler(event: IsCompleteRequest): Promise<IsCompleteResponse>; |
60 changes: 60 additions & 0 deletions
60
....snapshot/asset.1e025324752b3133dc230c4b8b8752f666b63c09cd4aa605ec2b322cc40def2e/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
....snapshot/asset.1e025324752b3133dc230c4b8b8752f666b63c09cd4aa605ec2b322cc40def2e/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* eslint-disable no-console */ | ||
import type { IsCompleteRequest, IsCompleteResponse, OnEventRequest, OnEventResponse } from '@aws-cdk/custom-resources/lib/provider-framework/types'; | ||
import { RDS } from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies | ||
|
||
export async function onEventHandler(event: OnEventRequest): Promise<OnEventResponse> { | ||
console.log('Event: %j', event); | ||
|
||
const rds = new RDS(); | ||
|
||
const physicalResourceId = `${event.ResourceProperties.DBClusterIdentifier}-${event.ResourceProperties.DBClusterIdentifier}`; | ||
|
||
if (event.RequestType === 'Create' || event.RequestType === 'Update') { | ||
const data = await rds.createDBClusterSnapshot({ | ||
DBClusterIdentifier: event.ResourceProperties.DBClusterIdentifier, | ||
DBClusterSnapshotIdentifier: event.ResourceProperties.DBClusterSnapshotIdentifier, | ||
}).promise(); | ||
return { | ||
PhysicalResourceId: physicalResourceId, | ||
Data: { | ||
DBClusterSnapshotArn: data.DBClusterSnapshot?.DBClusterSnapshotArn, | ||
}, | ||
}; | ||
} | ||
|
||
if (event.RequestType === 'Delete') { | ||
await rds.deleteDBClusterSnapshot({ | ||
DBClusterSnapshotIdentifier: event.ResourceProperties.DBClusterSnapshotIdentifier, | ||
}).promise(); | ||
} | ||
|
||
return { | ||
PhysicalResourceId: `${event.ResourceProperties.DBClusterIdentifier}-${event.ResourceProperties.DBClusterIdentifier}`, | ||
}; | ||
} | ||
|
||
export async function isCompleteHandler(event: IsCompleteRequest): Promise<IsCompleteResponse> { | ||
console.log('Event: %j', event); | ||
|
||
const snapshotStatus = await tryGetClusterSnapshotStatus(event.ResourceProperties.DBClusterSnapshotIdentifier); | ||
|
||
switch (event.RequestType) { | ||
case 'Create': | ||
case 'Update': | ||
return { IsComplete: snapshotStatus === 'available' }; | ||
case 'Delete': | ||
return { IsComplete: snapshotStatus === undefined }; | ||
} | ||
} | ||
|
||
async function tryGetClusterSnapshotStatus(identifier: string): Promise<string | undefined> { | ||
try { | ||
const rds = new RDS(); | ||
const data = await rds.describeDBClusterSnapshots({ | ||
DBClusterSnapshotIdentifier: identifier, | ||
}).promise(); | ||
return data.DBClusterSnapshots?.[0].Status; | ||
} catch (err) { | ||
if (err.code === 'DBClusterSnapshotNotFoundFault') { | ||
return undefined; | ||
} | ||
throw err; | ||
} | ||
} |
Oops, something went wrong.