Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): adding warnings to alert when properties will be overwritt…
…en (#33507) ### Issue # Closes #32468 ### Reason for this change When using a custom resource, the values for `serviceToken` and `serviceTimeout` are added to the construct prop `properties` during the synth. Thus passing those values through to the lambda. The issue is that these values can be overwritten if you also include the exact keys in your own properties argument. So if I include `serviceToken`, which is a required arg, then I set properties ``` properties: { ServiceToken: 'something else', }, ``` the value of `serviceToken` is set to `ServiceToken`, then my property I wrote to `ServiceToken` takes over and replaces the value with my own. This change is to add a warning to the user so they can understand that what they are doing is overwriting that key, as well as add some more detailed flavor text to the properties and readme to help convey this. ### Description of changes Previously the props like `serviceToken` were being written directly to properties, along with the user provided properties broken out with `...` notation. I moved the automatically added props out of this ``` const constructPropertiesPassed = { ServiceToken: props.serviceToken, ServiceTimeout: props.serviceTimeout?.toSeconds().toString(), }; const hasCommonKeys = Object.keys(properties).some(key => key in constructPropertiesPassed); if (hasCommonKeys) { Annotations.of(this).addWarningV2('@aws-cdk/core:customResourcePropDuplicate', `CustomResource properties should not contain keys that are automatically added by the CDK. Found: ${Object.keys(properties).filter(key => key in constructPropertiesPassed)}`); } this.resource = new CfnResource(this, 'Default', { type, properties: { ...constructPropertiesPassed, ...properties, }, }); ``` This allowed for a simple comparison between the 2 dicts, which allows for the warning to be initiated from. ### Description of how you validated changes I added a test to check if this warning is being generated. I did not change any integs because the actual synth in the end is the exact same as before. ### 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