Describe the bug
It is possible to create a CfnOutput in the CDK that synthesizes without issue, but then fails to deploy due to an invalid export name.
Expected Behavior
The CfnOutput exportName property should be validated according to the cloud formation rules at synthesis time to catch this problem sooner in the process.
Current Behavior
CDK synthesis works just fine, however during deployment Cloud Formation deployments will fail:
Deployment failed: Error [ValidationError]: Template format error: Output <SomeOutputNameHere> is malformed. The Name field of every Export member must be specified and consist only of alphanumeric characters, colons, or hyphens.
Reproduction Steps
import { CfnOutput, Stack } from 'aws-cdk-lib';
export class MyStack extends Stack {
constructor(...props: ConstructorParameters<typeof Stack>) {
super(...props);
new CfnOutput(this, 'id', {
value: 'SomeValue',
exportName: 'SOME_INVALID_EXPORT_NAME`,
});
}
}
Possible Solution
Validate the exportName field of the CfnOutput constructor props during synthesis. Possibly via a regex similar to [A-Za-z\d\-\:]*.
Additional Information/Context
I filed this under bug even though there isn't anything technically "wrong" with the CDK code because as a user, I would expect the synthesis to fail if something that can be validated to conform to cloud formation rules can be validated at synthesis time (and indeed in this case it appears at least on the surface that it can be).
CDK CLI Version
2.114.1
Framework Version
No response
Node.js Version
18
OS
MacOS 14 + Amazon Linux 2 5.10
Language
TypeScript
Language Version
5
Other information
No response
Describe the bug
It is possible to create a
CfnOutputin the CDK that synthesizes without issue, but then fails to deploy due to an invalid export name.Expected Behavior
The
CfnOutputexportNameproperty should be validated according to the cloud formation rules at synthesis time to catch this problem sooner in the process.Current Behavior
CDK synthesis works just fine, however during deployment Cloud Formation deployments will fail:
Reproduction Steps
Possible Solution
Validate the
exportNamefield of theCfnOutputconstructor props during synthesis. Possibly via a regex similar to[A-Za-z\d\-\:]*.Additional Information/Context
I filed this under bug even though there isn't anything technically "wrong" with the CDK code because as a user, I would expect the synthesis to fail if something that can be validated to conform to cloud formation rules can be validated at synthesis time (and indeed in this case it appears at least on the surface that it can be).
CDK CLI Version
2.114.1
Framework Version
No response
Node.js Version
18
OS
MacOS 14 + Amazon Linux 2 5.10
Language
TypeScript
Language Version
5
Other information
No response