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.

CloudFormationStack.template : Cannot read existing template

See original GitHub issue

Hi,

When I execute a cdk diff on my CDK project to get differences with an existing CloudFormation template (that was not initially generated by this project). In fact, it’s failing with some stacks and not all of them. It’s really hard to define why as we have no information one the root cause.

I have use the debug mode and verbose mode to have more information, and it’s not really helpful.

Reproduction Steps

My initial code :

const mainStackName: string = "my-stack-01";

  const mainStack = new MyLoaderStack(app, mainStackName, {
    env: {
      region: buildConfig.awsProfileRegion,
      account: buildConfig.awsAccountID
    }
  }, buildConfig);

If mainStackName is a CloudFormation that is not existing, it’s working in all case, if it exists, it fails for some of them but with a difficult reason to guess…

What actually happened?

For the CloudFormation that are not working well I have this output:

Stack my-stack-01
Reading existing template for stack my-stack-01.
Unexpected token A in JSON at position 0
SyntaxError: Unexpected token A in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.deserializeStructure (C:\Users\XXXX\AppData\Roaming\npm\node_modules\aws-cdk\lib\serialize.ts:19:17)
    at CloudFormationStack.template (C:\Users\XXXX\AppData\Roaming\npm\node_modules\aws-cdk\lib\api\util\cloudformation.ts:70:50)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at CdkToolkit.diff (C:\Users\XXXXX\AppData\Roaming\npm\node_modules\aws-cdk\lib\cdk-toolkit.ts:104:33)
    at initCommandLine (C:\Users\XXXXX\AppData\Roaming\npm\node_modules\aws-cdk\bin\cdk.ts:213:9)

If I made a test with a stack “my-stack-02”, that also exist (ie. already deployed on my AWS account like my-stack-01), it’s working well. But as I don’t understand this error and what could be wrong. I checked the remote CloudFormation templates, but I guess if their format was not correct, they will not be deployed on AWS CloudFormation…

Environment

  • **CDK CLI Version : 1.116.0
  • **Framework Version: 1.116.0
  • **Node.js Version: v14.17.4
  • **OS : Windows 10
  • **Language (Version): TypeScript 3.9.7

Other

aws synth is working as expected.


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
github-actions[bot]commented, Sep 6, 2021

⚠️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.

1reaction
blaoueillecommented, Sep 6, 2021

Hi, Yes but without using this migration feature, it was working well in other templates. I was not thinking it was absolutely mandatory to use the cfn-include in my case. I was more wondering why it was no able to deserialize the existing stack, there is no real way to debug or to see the output of the retrieved remote template. However, I have a workaround now (described in my previous post). Regards, Bruno

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting CloudFormation - AWS Documentation
To update an AWS CloudFormation stack, you must submit template or parameter value changes to AWS CloudFormation. However, AWS CloudFormation won't recognize ...
Read more >
10 Solutions to Common CloudFormation Errors - Medium
One of the most common errors encountered while using CloudFormation is a Syntax or Formatting Error. Your options for utilizing either JSON or ......
Read more >
CloudFormation — Boto3 Docs 1.26.36 documentation
The template defines a collection of resources as a single unit called a stack. CloudFormation creates and deletes all member resources of the...
Read more >
Removing Errors on CloudFormation Stack Creation - Stelligent
When CloudFormation fails during initial stack creation, it automatically rolls back the stack, and the stack cannot be recreated without ...
Read more >
How do I resolve template validation or template format errors ...
How to Create a VPC Using Cloudformation · CloudFormation Course for Beginners · How to avoid the AWS CloudFormation Resource Limit - Serverless ......
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