Aws-cdk: Multiple instances of CfnInclude cause TypeError

Created on 22 May 2020  路  3Comments  路  Source: aws/aws-cdk

Upon using cdk.CfnInclude multiple times, a TypeError is raised. The content or ordering of the templates doesn't appear to make a difference. Both the templates in the below example will synth correctly when used individually.

Reproduction Steps

import * as cdk from '@aws-cdk/core';
import * as fs from 'fs';
import * as YAML from 'yaml';

export class CdkStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new cdk.CfnInclude(this, "Artifacts", {
      template: YAML.parse(
        fs.readFileSync("../test1.yml").toString()
      ),
    });

    new cdk.CfnInclude(this, "Buckets", {
      template: YAML.parse(
        fs.readFileSync("../test2.yml").toString()
      ),
    });
}

Error Log

/Users/jd/git/admin/build/cdk/node_modules/@aws-cdk/core/lib/stack.ts:988
        if (id in dest) {
              ^
TypeError: Cannot use 'in' operator to search for '0' in 2010-09-09
    at merge (/Users/jd/git/admin/build/cdk/node_modules/@aws-cdk/core/lib/stack.ts:988:15)
    at CdkStack._toCloudFormation (/Users/jd/git/admin/build/cdk/node_modules/@aws-cdk/core/lib/stack.ts:846:7)
    at CdkStack.synthesize (/Users/jd/git/admin/build/cdk/node_modules/@aws-cdk/core/lib/stack.ts:762:38)
    at CdkStack.onSynthesize (/Users/jd/git/admin/build/cdk/node_modules/@aws-cdk/core/lib/construct-compat.ts:123:10)
    at Node.synthesize (/Users/jd/git/admin/build/cdk/node_modules/constructs/lib/construct.ts:407:28)
    at Function.synth (/Users/jd/git/admin/build/cdk/node_modules/@aws-cdk/core/lib/construct-compat.ts:231:22)
    at App.synth (/Users/jd/git/admin/build/cdk/node_modules/@aws-cdk/core/lib/app.ts:142:36)
    at process.<anonymous> (/Users/jd/git/admin/build/cdk/node_modules/@aws-cdk/core/lib/app.ts:121:45)
    at Object.onceWrapper (events.js:428:26)
    at process.emit (events.js:321:20)
Subprocess exited with error 1

Environment

  • CLI Version : 1.41.0 (build 9e071d2)
  • Framework Version: uncertain
  • OS : MacOS 10.15.1
  • Language : English

Other

Contents of the test templates:

test1.yml:

---
AWSTemplateFormatVersion: "2010-09-09"
Description: Test 1

Resources:
  DummyResource:
    Type: AWS::CloudFormation::WaitConditionHandle

test2.yml:

---
AWSTemplateFormatVersion: "2010-09-09"
Description: Test 2

Resources:
  DummyResource:
    Type: AWS::CloudFormation::WaitConditionHandle


This is :bug: Bug Report

@aws-cdcore bug p1

All 3 comments

Thanks for opening the issue @scarybot . Confirming this is a bug on our side. Will work on a fix.

BTW, you probably reduced the example to the minimum, but to be clear: your templates wouldn't work together anyway, because you use the same logical ID of DummyResource in both (our bug is somewhere else, but just to be clear 馃お).

BTW, you probably reduced the example to the minimum, but to be clear: your templates wouldn't work together anyway, because you use the same logical ID of DummyResource in both (our bug is somewhere else, but just to be clear 馃お).

Thanks, yes, I was just trying to be illustrative :D

Was this page helpful?
0 / 5 - 0 ratings