Aws-cdk: TS - Elasticsearch - Argument of type 'this' is not assignable to parameter of type 'Construct'

Created on 12 Oct 2018  路  7Comments  路  Source: aws/aws-cdk

I have a created a simple Stack that attempts to create an Elasticsearch domain, complete with cluster definition and EBS volume definition. though I receive the error Argument of type 'this' is not assignable to parameter of type 'Construct' . When I use any other resource like EC2, S3, SNS, or SQS I do not receive the error and the stacks are created and the properties are present. As of now, it happens only with Elasticsearch cloudformation.DomainResource. I ran this initially as a Javascript CDK project and cdk synth would appear to resolve, but on cdk deploy I would simply get a message that the resources that I setup in properties, appeared not to be recognized, but no other error before rollback. I switched to Typescript and received more meaningful feedback pretty quickly. I see that other have experienced similar issues that were resolved in previous version upgrades (#542 VPC and Subnets). The env versions and typescript code in use, is as follows


node version 8.11.3
npm version 5.6.0

cdk version 0.10.0 (build 60ef847)

!/usr/bin/env node

import cdk = require('@aws-cdk/cdk');
import elastic = require('@aws-cdk/aws-elasticsearch');

class ElasticCdkStack extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);

new elastic.cloudformation.DomainResource(this, 'MyTestElasticSearch', {
  DomainName : "es-test",
  ElasticsearchClusterConfig : {
      DedicatedMasterCount : 0,
      DedicatedMasterEnabled : false,
      InstanceCount : 1,
      InstanceType : "m4.large.elasticsearch",
      ZoneAwarenessEnabled : false
    },
  EBSOptions : {
      EBSEnabled : true,
      VolumeSize : 100,
      VolumeType : "gp2"
  },
  EncryptionAtRestOptions : {
      Enabled: false
  },
  SnapshotOptions : {
      AutomatedSnapshotStartHour : 0
  },
  ElasticsearchVersion : "6.3"
});

}
}

const app = new cdk.App(process.argv);
new ElasticCdkStack(app, 'ElasticCdkStack');
process.stdout.write(app.run());

bug

Most helpful comment

@bryanblackman please make sure you have both @aws-cdk/cdk and @aws-cdk/aws-elasticsearch on the same version, I suggest to just remove the ^ and use fixed versions. Also make sure it matches the global cdk cli, running cdk --version should tell you the version.

Had the same issue, solved by removing node_modules and matching all versions.

"devDependencies": {
    "@types/node": "8.9.4",
    "typescript": "3.1.2",
    "aws-cdk": "0.12.0"
  },
  "dependencies": {
    "@aws-cdk/aws-cognito": "0.12.0",
    "@aws-cdk/cdk": "0.12.0"
  }
$ cdk --version
0.12.0 (build 2dc324e)

Hope it helps

All 7 comments

Can you ensure all dependencies use the same version?

Yes, also updated from "@aws-cdk/aws-elasticsearch": "^0.11.0" to "@aws-cdk/aws-elasticsearch": "^0.12.0" and updated npm to 6.4 and ran a new npm install an rechecked issue .... same

Does the version of @aws-cdk/aws-elasticsearch match the version of @aws-cdk/cdk?

It would help if you could put a minimum reproducing example somewhere, for example in a fresh GitHub repository in your account?

@bryanblackman please make sure you have both @aws-cdk/cdk and @aws-cdk/aws-elasticsearch on the same version, I suggest to just remove the ^ and use fixed versions. Also make sure it matches the global cdk cli, running cdk --version should tell you the version.

Had the same issue, solved by removing node_modules and matching all versions.

"devDependencies": {
    "@types/node": "8.9.4",
    "typescript": "3.1.2",
    "aws-cdk": "0.12.0"
  },
  "dependencies": {
    "@aws-cdk/aws-cognito": "0.12.0",
    "@aws-cdk/cdk": "0.12.0"
  }
$ cdk --version
0.12.0 (build 2dc324e)

Hope it helps

@thaerlabs Thanks for the advice. I was using 0.10.0 with elasticsearch 0.12.0. I dropped back to elasticsearch 0.10.0 but then had other issues. I will use strict semantic versioning and update everything to 0.12.0 and try again. Thanks for the sanity check.

There were a few more issues where the documentation for elasticsearch appeared to be a bit misleading, but its working now. Thx to all @thaerlabs @eladb and @rix0rrr

Was this page helpful?
0 / 5 - 0 ratings