Commit 457aa99
authored
### Issue # (if applicable)
Closes #34397
### Reason for this change
[Dynamic references](https://docs.aws.amazon.com/secretsmanager/latest/userguide/cfn-example_reference-secret.html) allow an AWS Secrets Manager Secret to be retrieved for use in another AWS CloudFormation resource. Currently the key strings for dynamic references must be created using string manipulation, eg
```ts
const passwordKey = `${mySecret.secretArn}:SecretString:password`;
```
### Description of changes
The existing static [secretsManager](https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/core/lib/secret-value.ts#L98C17-L98C31) function in `aws-cdk-lib/core` includes code to generate a dynamic reference key string. This code was therefore extracted into a new static `cfnDynamicReferenceKey` function to make it available outside the `secretsManager` function. Using this new static function the above code example becomes
```ts
const passwordKey = SecretValue.cfnDynamicReferenceKey(mySecret.secretArn, { jsonField: 'password' });
```
A new instance method `cfnDynamicReferenceKey` was also created in the [Secret](https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-secretsmanager/lib/secret.ts#L499) class in `aws-cdk-lib/aws-secretsmanager`, which calls the new static `cfnDynamicReferenceKey` function for the secret that it represents. Using this new instance method the above example becomes
```ts
const passwordKey = mySecret.cfnDynamicReferenceKey({ jsonField: 'password' });
```
### Description of how you validated changes
Unit tests and an integration test.
### 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 f7b5d8c commit 457aa99
File tree
14 files changed
+1011
-3
lines changed- packages
- @aws-cdk-testing/framework-integ/test/aws-secretsmanager/test
- integ.secret.dynamic-reference-key.js.snapshot
- aws-cdk-lib
- aws-secretsmanager
- lib
- test
- core
- lib
- test
14 files changed
+1011
-3
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments