-
Notifications
You must be signed in to change notification settings - Fork 268
Lack of Type Safety for some incoming CDK Props interfaces #1463
Description
AWS Solutions Constructs allows you to override any individual default property on a resource being created by a construct, by accepting a standard CDK Props object for that resource. For example, if you want to set the visibilityTimeout for the SQS queue in aws-sns-sqs construct, you can send a Props object with just that value provided:
new SnsToSqs(this, 'SnsToSqsPattern', {
queueProps: {
visibilityTimeout: Duration.hours(1)
}
});
This works well when every value in a Props object is optional, but some Props objects include required attributes. Some of these required attributes require a lot of effort to provide - especially if you just want to specify a fixed resource name. To accomodate this, any Props object accepted by construct that includes required properties is defined with | any in the type. For instance:
export interface CloudFrontToS3Props {
/**
* Optional user provided props to override the default props
*
* @default - Default props are used
*/
readonly cloudFrontDistributionProps?: cloudfront.DistributionProps | any,
...
}
While this allows you to provide any subset of DistributionProps attributes, it effectively destroys type safety (we cannot use Partial here, as it is not supported by the JSII technology that allows us to publish for multiple languages). This can lead to very subtle bugs:
new CloudFrontToS3Props(this, 'test', {
cloudFrontDistributionProps: {
// The actual property name is priceClass
PriceClass: PriceClass.PRICE_CLASS_100
}
})
The incorrect property name (PriceClass instead of priceClass) results in the property being ignored and the distribution using PRICE_CLASS_ALL.
We are working to address this issue by providing run time checking of incoming Props attributes and flagging incorrect property names. This feature should be released very soon.
This is 🐛 Bug Report