Skip to content

Commit 3c92012

Browse files
authored
feat(rds): enable grantDataApiAccess method for imported database cluster (#31280)
### Issue # (if applicable) Closes #31116 . ### Reason for this change It was not possible to call the `grantDataApiAccess` method for an imported database cluster. Because the imported database cluster always has the `enableDataApi` with false. https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-rds/lib/cluster.ts#L983 ```ts class ImportedDatabaseCluster extends DatabaseClusterBase implements IDatabaseCluster { // ... protected readonly enableDataApi = false; ``` But the `grantDataApiAccess` throws an error when the `enableDataApi` is set to false. https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-rds/lib/cluster.ts#L523-L526 ```ts public grantDataApiAccess(grantee: iam.IGrantable): iam.Grant { if (this.enableDataApi === false) { throw new Error('Cannot grant Data API access when the Data API is disabled'); } // ... } ``` ### Description of changes Added the property `dataApiEnabled` to attributes for the imported database cluster. If the `dataApiEnabled` to the attributes is set to true, the `enableDataApi` in the imported cluster will be set to true and the `grantDataApiAccess` can be called. ### Description of how you validated changes Unit and integ tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 19ee46d commit 3c92012

15 files changed

+2840
-1
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.cluster-data-api-to-imported-cluster.js.snapshot/asset.bde7b5c89cb43285f884c94f0b9e17cdb0f5eb5345005114dd60342e0b8a85a1/__entrypoint__.js

+155
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.cluster-data-api-to-imported-cluster.js.snapshot/asset.bde7b5c89cb43285f884c94f0b9e17cdb0f5eb5345005114dd60342e0b8a85a1/index.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.cluster-data-api-to-imported-cluster.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.cluster-data-api-to-imported-cluster.js.snapshot/cluster-data-api-to-imported-cluster.assets.json

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)