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.

CfnCondition is instance of Construct

See original GitHub issue

I’m wondering why a the Construct Condition in an AWS template is an instanceof software.amazon.awscdk.core.Construct and not and instanceof CfnCondition?

Reproduction Steps

Given the java code:

CfnInclude template;
List<IConstruct> lic = template.getNode().getChildren();
for (IConstruct IC : lic) {
  LOG.debug("TemplateToTreeMap class name " + IC.getClass().getTypeName());
  if (IC instanceof CfnCondition) {
    LOG.debug("IC is instanceof of CfnCondition");
  }else if (IC instanceof CfnParameter) {
    LOG.debug("IC is instanceof of CfnParameter");
  }
}

When the Construct is a template Condition it is an instanceof software.amazon.awscdk.core.Construct rather than a CfnCondition which differs from the case when the Construct is a CfnParameter which is an instanceof CfnParameter.

Both CfnCondition and CfnParameter extend CfnElement.

Why does that happen and how then do I identify a Condition?

Alternatively I’ve tried as a work around the following:

if (IC.toString().contains("$Conditions")) { LOG.debug(IC.toString()); Construct C = (Construct) IC; LOG.debug(toJsonString(C.getNode())); LOG.debug(stack.resolve(C).toString());

Which gives output as follows

AwsCdkStack/Template/$Conditions ${Token[TOKEN.646]}

But then results in an error

software.amazon.jsii.JsiiException: 

Unable to resolve object tree with circular reference. Path: /node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node Error: Unable to resolve object tree with circular reference. Path: /node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node/host/node at resolve (/tmp/jsii-kernel-w8xgCb/node_modules/@aws-cdk/core/lib/private/resolve.js:35:15) at Object.resolve (/tmp/jsii-kernel-w8xgCb/node_modules/@aws-cdk/core/lib/private/resolve.js:29:33) at resolve (/tmp/jsii-kernel-w8xgCb/node_modules/@aws-cdk/core/lib/private/resolve.js:118:43) at Object.resolve (/tmp/jsii-kernel-w8xgCb/node_modules/@aws-cdk/core/lib/private/resolve.js:29:33) at resolve (/tmp/jsii-kernel-w8xgCb/node_modules/@aws-cdk/core/lib/private/resolve.js:118:43) at Object.resolve (/tmp/jsii-kernel-w8xgCb/node_modules/@aws-cdk/core/lib/private/resolve.js:29:33) at resolve (/tmp/jsii-kernel-w8xgCb/node_modules/@aws-cdk/core/lib/private/resolve.js:118:43) at Object.resolve (/tmp/jsii-kernel-w8xgCb/node_modules/@aws-cdk/core/lib/private/resolve.js:29:33) at resolve (/tmp/jsii-kernel-w8xgCb/node_modules/@aws-cdk/core/lib/private/resolve.js:118:43) at Object.resolve (/tmp/jsii-kernel-w8xgCb/node_modules/@aws-cdk/core/lib/private/resolve.js:29:33) at com.iriusrisk.cfimport.BasicApplicationTests.Example1_1(BasicApplicationTests.java:29)

What did you expect to happen?

The Template Condition to be a CfnCondition

What actually happened?

The Template condition was an instanceof Construct

Environment

<dependency> <groupId>software.amazon.awscdk</groupId> <artifactId>cdk-cloudformation-include</artifactId> <version>1.86.0</version> </dependency> <dependency> <groupId>software.amazon.jsii</groupId> <artifactId>jsii-runtime</artifactId> <version>1.20.1</version> </dependency>
  • CDK CLI Version :1.79
  • Framework Version:1.86.0
  • Node.js Version:v14.15.3
  • OS : Ubuntu 18.04
  • Language (Version):Java 8–>

Other


This is 🐛 Bug Report

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jahtoecommented, Feb 8, 2021

@skinny85 we are done thanks again

0reactions
github-actions[bot]commented, Feb 8, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class CfnCondition (construct) · AWS ... - AWS Documentation
The condition must be constructed with a condition token, that the condition is based on. Construct Props. Name, Type, Description. expression?
Read more >
Why is a template condition: not an instanceof CfnCondition?
I'm wondering why a condition in an AWS template is an instance of software.amazon.awscdk.core.Construct and not an instance of CfnCondition .
Read more >
Create resources conditionally with CDK - Luciano Mammino
In short, we will learn about the CfnCondition construct and how it can be used to create CloudFormation conditions. Then we will see...
Read more >
aws-cdk-lib - npm
The AWS CDK construct library provides APIs to define your CDK ... An instance of Duration is constructed by using one of the...
Read more >
How to use the @aws-cdk/core.Construct.isConstruct function ...
if (!Construct.isConstruct(this.queue)) { throw new Error(`The supplied Queue object must be an instance of Construct`); } // add a statement to the queue ......
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