From 5aa92ddbefb807bff48fb8d2545fbaa6f4db92ce Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Tue, 19 Mar 2024 12:08:27 -0700 Subject: [PATCH] fix: improve type annotation for CustomResource properties My team just went on quite the adventure trying to figure out why JSON `false` values where getting converted to `"false"`. It would have been really nice if cdk's typing could have prevented that bug in the first place. (It would be even nicer if the underlying CloudFormation bug were fixed, but this is better than nothing) --- packages/aws-cdk-lib/core/lib/custom-resource.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/core/lib/custom-resource.ts b/packages/aws-cdk-lib/core/lib/custom-resource.ts index 5e77f7f77e220..7ae07c1b469df 100644 --- a/packages/aws-cdk-lib/core/lib/custom-resource.ts +++ b/packages/aws-cdk-lib/core/lib/custom-resource.ts @@ -4,6 +4,13 @@ import { RemovalPolicy } from './removal-policy'; import { Resource } from './resource'; import { Token } from './token'; +// Note that CloudFormation only supports the subset of JSON where the leaf nodes are strings. +// See https://github.com/aws/aws-cdk-rfcs/issues/375 for details. +type StringOnlyJsonValue = + | string + | { [x: string]: StringOnlyJsonValue } + | Array; + /** * Properties to provide a Lambda-backed custom resource */ @@ -57,10 +64,12 @@ export interface CustomResourceProps { /** * Properties to pass to the Lambda + * Note that CloudFormation only supports the subset of JSON where the leaf + * nodes are strings. See https://github.com/aws/aws-cdk-rfcs/issues/375 for details. * * @default - No properties. */ - readonly properties?: { [key: string]: any }; + readonly properties?: { [key: string]: StringOnlyJsonValue }; /** * For custom resources, you can specify AWS::CloudFormation::CustomResource