CloudFormationStack.template : Cannot read existing template
See original GitHub issueHi,
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:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
⚠️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.
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