Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(core): CfnOutput does not validate export name during synthesis but can fail during deployment #28563

Closed
The-Zona-Zoo opened this issue Jan 3, 2024 · 2 comments · Fixed by #28575
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@The-Zona-Zoo
Copy link

The-Zona-Zoo commented Jan 3, 2024

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

@The-Zona-Zoo The-Zona-Zoo added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 3, 2024
@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label Jan 3, 2024
@pahud
Copy link
Contributor

pahud commented Jan 4, 2024

Yes we definitely should validate it in CDK. Thanks for the report and we welcome PRs from the community.

@pahud pahud added p2 effort/medium Medium work item – several days of effort effort/small Small work item – less than a day of effort and removed effort/medium Medium work item – several days of effort needs-triage This issue or PR still needs to be triaged. labels Jan 4, 2024
@mergify mergify bot closed this as completed in #28575 Jan 23, 2024
mergify bot pushed a commit that referenced this issue Jan 23, 2024
Closes #28563.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants