AWS CDK ERROR: There is already a Construct with name ‘XYZ’

When I was running AWS CDK, I got this error and couldn’t really find the answer when I googled it. This error might happen for different reasons, but I worked out what was wrong with my CDK code after a few hours of googling and trying out different things. I’m hoping this post will save you hours going crazy on this mystery error message.

Error

Error is thrown in construct.ts as below.

throw new Error(`There is already a Construct with name '${childName}' 
in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`);

Error: There is already a Construct with name 'XYZ' in XYZStack

Solution

In stack, each construct requires to have a unique id. In my original code, I was just passing the id two both construct, which was causing this error.

constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // The code that defines your stack goes here
    new S3Bucket(this, id);
    new ConnectDataKinesisStream(this, id);
  }

The solution to make this id unique. I added the resource suffix. But, this can be whatever as long as each construct has different id.

constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // The code that defines your stack goes here
    new S3Bucket(this, id + '-s3');
    new ConnectDataKinesisStream(this, id + '-kinesis');
  }

This is it. Error’s gone. Happy building!

Git
How to specify which Node version to use in Github Actions

When you want to specify which Node version to use in your Github Actions, you can use actions/setup-node@v2. The alternative way is to use a node container. When you try to use a publicly available node container like runs-on: node:alpine-xx, the pipeline gets stuck in a queue. runs-on is not …

AWS
Using semantic-release with AWS CodePipeline and CodeBuild

Here is the usual pattern of getting the source from a git repository in AWS CodePipeline. In the pipeline, we use AWS CodeStart to connect to a repo and get the source. Then, we pass it to the other stages, like deploy or publish. For some unknown reasons, CodePipeline downloads …

DBA
mysqldump Error: Unknown table ‘COLUMN_STATISTICS’ in information_schema (1109)

mysqldump 8 enabled a new flag called columm-statistics by default. When you have MySQL client above 8 and try to run mysqldump on older MySQL versions, you will get the error below. mysqldump: Couldn’t execute ‘SELECT COLUMN_NAME, JSON_EXTRACT(HISTOGRAM ‘$”number-of-buckets-specified”‘) FROM information_schema.COLUMN_STATISTICS WHERE SCHEMA_NAME = ‘myschema’ AND TABLE_NAME = ‘craue_config_setting’;’: Unknown …