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

aws-cdk-notices: CDK Notice being parsed incorrectly causing YAMLSemanticError #33589

Open
1 task done
frankpengau opened this issue Feb 26, 2025 · 17 comments · May be fixed by aws/aws-cdk-cli#188
Open
1 task done

aws-cdk-notices: CDK Notice being parsed incorrectly causing YAMLSemanticError #33589

frankpengau opened this issue Feb 26, 2025 · 17 comments · May be fixed by aws/aws-cdk-cli#188
Assignees
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. p1 potential-regression Marking this issue as a potential regression to be checked by team member skip-abstractions-board signal to automated workflow to skip adding to project board

Comments

@frankpengau
Copy link
Contributor

Describe the bug

When running a CDK Deploy, due to the CDK Notice, it seems to be picked up and parsed by YAML?

This causes a YAMLSemanticError to be produced within one of aws-cdk yaml dependencies.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

2.177.0

Expected Behavior

CDK Deploy should not fail on YAMLSemanticError.

Current Behavior

Error Log Output after CDK Deploy:

/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1856
                doc.errors.push(new PlainValue.YAMLSemanticError(item, msg));
                                ^
YAMLSemanticError: Implicit map keys need to be followed by map values
    at resolveBlockMapItems (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1856:33)
    at Object.resolveMap [as resolve] (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1658:79)
    at resolveByTagName (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1430:25)
    at resolveTag (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1460:17)
    at resolveNodeValue (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1581:23)
    at Object.resolveNode (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1629:15)
    at parseContents (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/Document-9b4560a1.js:357:30)
    at Document.parse (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/Document-9b4560a1.js:615:5)
    at parseDocument (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/index.js:44:37)
    at Object.parse (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/index.js:55:15) {
  source: PlainValue {
    error: null,
    range: Range { start: 21443, end: 21531 },
    valueRange: Range { start: 21443, end: 21531 },
    props: [],
    type: 'PLAIN',
    value: null,
    resolved: Scalar {
      value: "\x1B[37mNOTICES         (What's this? https://github.com/aws/aws-cdk/wiki/CLI-Notices)\x1B[39m",
      range: [Array],
      type: 'PLAIN'
    }
  }
}
[06:22:00] failed command: npx ts-node ./src/index.ts

Reproduction Steps

npx aws-cdk deploy

Possible Solution

Stop CDK notices from being picked up by aws-cdk-lib yaml for parsing.

Additional Information/Context

Have tried using environment variable: CDK_NOTICES=false as suggested, but it doesn't ignore it.

Ref: https://github.com/aws/aws-cdk/wiki/CLI-Notices#what-if-i-dont-want-notices

CDK CLI Version

2.1000.3

Framework Version

No response

Node.js Version

22.14.0

OS

Amazon Linux 2

Language

TypeScript

Language Version

TypeScript (5.3.3)

Other information

Node 22.14.0 / NPM 10.9.2

@frankpengau frankpengau added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 26, 2025
@github-actions github-actions bot added aws-cdk-lib Related to the aws-cdk-lib package potential-regression Marking this issue as a potential regression to be checked by team member labels Feb 26, 2025
@frankpengau
Copy link
Contributor Author

Sorry in advance if this isn't the right place.

Not too sure where would be the most appropriate to raise the issue and thought it would be best to raise it here due to the yaml dependency of aws-cdk-lib seemingly being the one that is causing the error.

Please let me know if you prefer me to raise in the other relevant repos:

@mrgrain
Copy link
Contributor

mrgrain commented Feb 26, 2025

All good, thanks for raising this @frankpengau looking into it right now

@mrgrain
Copy link
Contributor

mrgrain commented Feb 26, 2025

@frankpengau I cannot reproduce this with a basic, newly created app (via cdk init).

  • Could you share something about your app?
  • What version of aws-cdk-lib are you using?
  • Are you using any constructs that might not be considered simple?
  • Are you using any third constructs?
  • Does this also happen when you run cdk synth -q?
  • Can you share the output of cdk deploy --debug -vvv with me?

Thanks!

@mrgrain
Copy link
Contributor

mrgrain commented Feb 26, 2025

Also checked for constructs that use the yaml package and these came up:

  • aws-codebuild
  • aws-eks
  • cloudformation-include
  • @aws-cdk/aws-eks-v2-alpha

Are you using any of these in your app?

@ashishdhingra ashishdhingra added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Feb 26, 2025
@zain-siddiqui24602
Copy link

zain-siddiqui24602 commented Feb 27, 2025

I was facing the same issue while deployment where when the NOTICE was being printed in stdout then the deployment was failing due to parsing error, to bypass this, I modified my Jenkinsfile to execute the command as cdk deploy --no-notices.

@rix0rrr
Copy link
Contributor

rix0rrr commented Feb 27, 2025

EDIT: nevermind

Can you run the above command again with

export NODE_OPTIONS=--stack-trace-limit=1000

?

I'd like to figure out where the YAML parse is coming from.

@mrgrain
Copy link
Contributor

mrgrain commented Feb 27, 2025

@zain-siddiqui24602 Could you share your dependencies with us and answer some of the questions I posted earlier?

@mrgrain mrgrain closed this as completed Feb 27, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2025
@mrgrain mrgrain reopened this Feb 27, 2025
@aws aws unlocked this conversation Feb 27, 2025
@aws aws deleted a comment from github-actions bot Feb 27, 2025
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 27, 2025
@pennyZZZZ
Copy link

Hey, I was facing the same issue. I tried setting the notices to false, which disabled the top-level notice; however, it appears that the notices are still coming from a nested structure, so I continue to receive the error. The cdk synth command runs without any problems. My construct contains several StackSets.

cdk.json
{
  "app": "npx ts-node ./src/index.ts",
  "notices": "false"
}
"dependencies": {
  "cdk-stacksets": "^0.0.150"
}

error output attached

output.md

@mrgrain
Copy link
Contributor

mrgrain commented Feb 28, 2025

@pennyZZZZ Thank you, this is super helpful. Could you please to run this with an extended stack trace and post the full output?

export NODE_OPTIONS=--stack-trace-limit=1000
cdk deploy

@frankpengau @zain-siddiqui24602 Are you also using cdk-stacksets? Are you getting this error locally or in CI?


I could see this issue occuring when cdk synth is run in a CI system, and the output template is written to a file/used to deploy a stack directly. To reproduce, this command produces an invalid YAML file. Still unclear what is using the result though.

CI=1 npx aws-cdk@2.150.0 synth > template.yaml

@frankpengau
Copy link
Contributor Author

@frankpengau I cannot reproduce this with a basic, newly created app (via cdk init).

  • Could you share something about your app?
  • What version of aws-cdk-lib are you using?
  • Are you using any constructs that might not be considered simple?
  • Are you using any third constructs?
  • Does this also happen when you run cdk synth -q?
  • Can you share the output of cdk deploy --debug -vvv with me?

Thanks!

Sorry @mrgrain, still trying to create a full reproduction without involving company private libraries.

Custom cdk app with aws-cdk-lib and alpha @aws-cdk libraries using L2 constructs.

aws-cdk-lib v2.180.0

Haven't been able to reproduce with cdk synth -q .

Will try and remove sensitive data and publish output for verbose logs for cdk deploy later.

Also checked for constructs that use the yaml package and these came up:

  • aws-codebuild
  • aws-eks
  • cloudformation-include
  • @aws-cdk/aws-eks-v2-alpha

Are you using any of these in your app?

Not using any of the packages listed.

@frankpengau
Copy link
Contributor Author

@frankpengau @zain-siddiqui24602 Are you also using cdk-stacksets? Are you getting this error locally or in CI?

Have seen it on a repo that extends off constructs for cdk-stacksets, but also have seen it on another cdk app repo that uses L2 constructs for aws-cdk-lib.

@pennyZZZZ
Copy link

@mrgrain Hey, here is the extended stack trace

/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1856
                doc.errors.push(new PlainValue.YAMLSemanticError(item, msg));
                                ^
YAMLSemanticError: Implicit map keys need to be followed by map values
    at resolveBlockMapItems (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1856:33)
    at Object.resolveMap [as resolve] (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1658:79)
    at resolveByTagName (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1430:25)
    at resolveTag (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1460:17)
    at resolveNodeValue (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1581:23)
    at Object.resolveNode (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/resolveSeq-d03cb037.js:1629:15)
    at parseContents (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/Document-9b4560a1.js:357:30)
    at Document.parse (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/Document-9b4560a1.js:615:5)
    at parseDocument (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/index.js:44:37)
    at Object.parse (/app/node_modules/aws-cdk-lib/node_modules/yaml/dist/index.js:55:15)
    at parseYamlStrWithCfnTags (/app/node_modules/aws-cdk-lib/cloudformation-include/lib/private/yaml-cfn.js:1:1206)
    at Object.deserialize (/app/node_modules/aws-cdk-lib/cloudformation-include/lib/private/yaml-cfn.js:1:529)
    at Object.readYamlSync (/app/node_modules/aws-cdk-lib/cloudformation-include/lib/file-utils.js:1:494)
    at new CfnInclude (/app/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.js:1:1317)
    at new CDKBootstrap (/app/src/StackSets/CDKBootstrap.ts:9:5)
    at new MyOrgStackSets (/app/src/stack.ts:62:33)
    at Object.<anonymous> (/app/src/index.ts:23:1)
    at Module._compile (node:internal/modules/cjs/loader:1562:14)
    at Module.m._compile (/app/node_modules/ts-node/src/index.ts:1618:23)
    at node:internal/modules/cjs/loader:1699:10
    at Object.require.extensions.<computed> [as .ts] (/app/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1313:32)
    at Function._load (node:internal/modules/cjs/loader:1123:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
    at phase4 (/app/node_modules/ts-node/src/bin.ts:649:14)
    at bootstrap (/app/node_modules/ts-node/src/bin.ts:95:10)
    at main (/app/node_modules/ts-node/src/bin.ts:55:10)
    at Object.<anonymous> (/app/node_modules/ts-node/src/bin.ts:800:3)
    at Module._compile (node:internal/modules/cjs/loader:1562:14)
    at Object.<anonymous> (node:internal/modules/cjs/loader:1699:10)
    at Module.load (node:internal/modules/cjs/loader:1313:32)
    at Function._load (node:internal/modules/cjs/loader:1123:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
    at node:internal/main/run_main_module:36:49 {
  source: PlainValue {
    error: null,
    range: Range { start: 21443, end: 21531 },
    valueRange: Range { start: 21443, end: 21531 },
    props: [],
    type: 'PLAIN',
    value: null,
    resolved: Scalar {
      value: "\x1B[37mNOTICES         (What's this? https://github.com/aws/aws-cdk/wiki/CLI-Notices)\x1B[39m",
      range: [Array],
      type: 'PLAIN'
    }
  }
}

@mrgrain
Copy link
Contributor

mrgrain commented Mar 3, 2025

Thanks @pennyZZZZ appreciate the details. Can you share the content of this file with us? It seems to be the source of the call, and appears to be a file that's not part of the CDK itself.

/app/src/StackSets/CDKBootstrap.ts

@pennyZZZZ
Copy link

@mrgrain yeah sure

export class CDKBootstrap extends StackSetStack {
  constructor(scope: core.RqpStack, id: string, props?: StackSetStackProps) {
    super(scope, id, props)

    new cloudformation_include.CfnInclude(this, 'CDKBootstrapRawTemplate', {
      templateFile: './src/StackSets/CDKBootstrap/cdk-bootstrap.template.yml',
    })
}

and the cdk-bootstrap.template.yml is generated by cdk bootstrap

@mrgrain
Copy link
Contributor

mrgrain commented Mar 3, 2025

Thank you @pennyZZZZ ! When you are running cdk bootstrap --show-template you need to pass --no-notices to it:

cdk bootstrap --no-notice --show-template

@frankpengau @zain-siddiqui24602 Are you doing something similar in your code?

@mrgrain mrgrain added p1 and removed p2 labels Mar 3, 2025
@godwingrs22 godwingrs22 added the skip-abstractions-board signal to automated workflow to skip adding to project board label Mar 3, 2025
@pennyZZZZ
Copy link

Hey @mrgrain, thanks for your help—it works perfectly! I just wanted to clarify that the correct flag is --no-notices. Thanks again!
Ref: https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping-env.html#bootstrapping-howto

@mrgrain
Copy link
Contributor

mrgrain commented Mar 4, 2025

Thanks @pennyZZZZ Updated my post.

While adding --no-notices to the call is a good workaround, we are also investigating longer term solutions.

rix0rrr added a commit to aws/aws-cdk-cli that referenced this issue Mar 4, 2025
On CI systems, the CDK CLI tries to avoid writing to `stderr` because
there are a couple of CI systems that are commonly configured to fail if
any output is written to `stderr`. That means all output, like notices,
must go to `stdout`.

Some commands (like `cdk synth` or `cdk bootstrap --show-template`)
produce usable output on `stdout`, and these are commonly scripted, like
piping their output to a file.

However, because notices must go to `stdout`, these now interfere with
the output of these commands.

This needs a more thorough reworking of the CLI output streams, but
there is a risk of affecting users who are currently relying on the fact
that all output goes to `stdout`.

In this PR, we are doing the first steps to solving this situation:

- Notices will always go to `stderr`, so that they will never interfere
  with `stdout` anymore.
- We try to detect what CI system we are running on, and we will
  completely suppress notices *unless* we determine that we are running
  on a CI system where it is "safe" to write to `sterr` (fail closed).

"Safe" in this case means that the CI system doesn't come with an easy
to toggle checkbox that makes commands fail based on what they print,
instead of their exit codes. The only systems I'm aware of that have
this checkbox are "Azure DevOps", and "TeamCity running PowerShell
scripts".

Even though we know the systems that are "unsafe", we will only
show notices on systems known to be "safe".

Fixes aws/aws-cdk#33589.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. p1 potential-regression Marking this issue as a potential regression to be checked by team member skip-abstractions-board signal to automated workflow to skip adding to project board
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants