If you are using Typescript, this is possible. I assume it is possible for other languages as well if we use similar casting tricks.
In the CDK Github, we see that AwsCustomResource has an underlying CustomResource member: https://github.com/aws/aws-cdk/blob/d7e4b7a7009aa03a81902266313c521b12b12d25/packages/aws-cdk-lib/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts#L397
We also see that CustomResource has an underlying CfnResource member: https://github.com/aws/aws-cdk/blob/d7e4b7a7009aa03a81902266313c521b12b12d25/packages/aws-cdk-lib/core/lib/custom-resource.ts#L126
CfnResource is the class that provides the cfnOptions member where you can set a resource's condition. Both AwsCustomResource.customResource
and CustomResource.resource
have private visibility, but we can circumvent this by casting the objects to any
. When all is said and done:
(((myCustomResource as any).customResource as any).resource as CfnResource).cfnOptions.condition = myCondition;