Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kms): allow
fromLookup
method to return dummy key if target ke…
…y was not found (#31676) ### Issue # (if applicable) Closes #31574. ### Reason for this change The `fromLookup` method causes an error if the target key was not found. However it would be also good not to cause an error in that case. ### Description of changes Added `returnDummyKeyOnMissing` in `KeyLookupOptions`. If the property is set to true, the context method will not cause an error and will return a dummy key if the key was not found. Originally, I thought to make the method to return undefined in that case, but the return type of method is `IKey`. If we change the type to `IKey | undefined`, it should be a breaking change. ```ts public static fromLookup(scope: Construct, id: string, options: KeyLookupOptions): IKey { ``` So I decided to return a dummy key with a dummy key id '1234abcd-12ab-34cd-56ef-1234567890ab'. The dummy key id had been defined originally (see: https://github.com/aws/aws-cdk/blob/v2.161.0/packages/aws-cdk-lib/aws-kms/lib/key.ts#L686). The property `returnDummyKeyOnMissing` will be passed to `ignoreErrorOnMissingContext` added in the [PR](#31415). If the `ignoreErrorOnMissingContext` is true and the key doesn't exist, an error will be suppressed in the `ContextProvider`. ### Additional information see: #31574 (comment) ### Description of how you validated changes Both of 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*
- Loading branch information