Skip to content

Commit

Permalink
fix: improve type annotation for CustomResource properties
Browse files Browse the repository at this point in the history
My team just went on quite the adventure trying to figure out why
JSON `false` values where getting converted to `"false"`. It would have
e 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)
  • Loading branch information
jfly committed Mar 19, 2024
1 parent 4ff3565 commit 1225f8a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/aws-cdk-lib/core/lib/custom-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StringOnlyJsonValue>;

/**
* Properties to provide a Lambda-backed custom resource
*/
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1225f8a

Please # to comment.