question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cdk diff (and cdk deploy) complains about short functions in existing yaml

See original GitHub issue

I have a stack deployed with an authored YAML template that uses short functions like !GetAtt. I am trying to convert this template to CDK, but cdk diff strips them.

Reproduction Steps

  1. Deploy a stack with a YAML file that uses !GetAtt authored outside of CDK
  2. Re-create that stack using CDK, generating the same Fn::GetAtt references
  3. Run cdk diff my-stack

Error Log

(node:2590) YAMLWarning: The tag !GetAtt is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !Ref is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !Ref is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !GetAtt is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !ImportValue is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !Ref is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !GetAtt is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !Sub is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !Ref is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !ImportValue is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !ImportValue is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !FindInMap is unavailable, falling back to tag:yaml.org,2002:seq

The !Fn is stripped, so the diff acts as if Prop: !GetAtt Thing.myAtt is actually the string Prop: Thing.myAtt

 │      [-]     "value": "MyKey.SecretAccessKey",
 │      [+]     "value": {
 │      [+]       "Fn::GetAtt": [
 │      [+]         "MyKey",
 │      [+]         "SecretAccessKey"
 │      [+]       ]
 │      [+]     },

Environment

  • CLI Version :1.26.0
  • Framework Version:
  • OS :MacOS
  • Language :Typescript

Other

Here’s my workaround for this.

Use cfn-flip to flip it to JSON:

aws cloudformation get-template --stack-name my-stack | jq ".TemplateBody" -r | cfn-flip -i yaml > cdk.out/my-stack.orig.json

Then, use cdk diff to compare to that:

 diff my-stack --template ./cdk.out/my-stack.orig.json

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
skinny85commented, Jun 26, 2020

@comcalvi has actually added support for CloudFormation short-forms in this PR: #8746 .

We’ll probably have to extract his logic after that PR is merged to use the same YAML parsing in the cdk diff command.

0reactions
jfrconleycommented, Apr 20, 2020

Encountering this same issue when using CfnInclude on an existing template. Issue persists even after using cfn-flip to convert to JSON beforehand. Seems like the yaml generator used internally is not setup with the required custom tags for cloudformation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS CDK Toolkit (cdk command) - AWS Documentation
cdk diff. Compares the specified stack and its dependencies with the deployed stacks or a local CloudFormation template. cdk metadata.
Read more >
Convert existing CDK App into CDK Pipeline - Stack Overflow
Yes. The important point here is that "local" and "pipeline" deploys have different construct hierarchies: local: App > (CoreStack ...
Read more >
Cdk use existing vpc - Seba Online
Import Existing VPCs and Subnets into a CDK Python Project The AWS CDK makes it ... Folks, you are doing a great job....
Read more >
Finally, the end of YAML? AWS CDK for Serverless - Medium
This allows developers familiar with these languages to apply their existing knowledge and get to grips with building Cloud infrastructure ...
Read more >
Why I (Still) Like the Serverless Framework over the CDK
The Serverless Framework is the most popular tool for deploying serverless applications, but the AWS CDK has been building momentum.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found