6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS CDKで「No stack could be identified for the construct at path」ってエラーでハマるなど

Posted at

AWS CDKを利用していて下記のエラーが発生してハマっていました。

No stack could be identified for the construct at path
pathのコンストラクトに対してスタックを識別できませんでした(Google翻訳) だそうです。

> cdk synth -v
(略)
No stack could be identified for the construct at path
Subprocess exited with error 1
Error: Subprocess exited with error 1
    at ChildProcess.proc.on.code (/Users/xxx/.anyenv/envs/ndenv/versions/v10.11.0/lib/node_modules/aws-cdk/lib/api/cxapp/exec.ts:110:23)
    at ChildProcess.emit (events.js:182:13)
    at ChildProcess.EventEmitter.emit (domain.js:442:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)

エラー再現

環境構築は以下のような感じ。AWS CDKは利用できる前提で。

> cdk --version
1.2.0 (build 6b763b7)


> mkdir cdk-error-test
> cd cdk-error-test

> cdk init app --language=typescript

実装は以下となります。Outputs の定義のみ。

lib/cdk-error-test-stack.ts
import cdk = require('@aws-cdk/core');

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

    new cdk.CfnOutput(scope, 'hoge', { value: 'hoge' });
  }
}

そしてエラーとなります。

> cdk synth -v
(略)
No stack could be identified for the construct at path
Subprocess exited with error 1
Error: Subprocess exited with error 1
    at ChildProcess.proc.on.code (/Users/xxx/.anyenv/envs/ndenv/versions/v10.11.0/lib/node_modules/aws-cdk/lib/api/cxapp/exec.ts:110:23)
    at ChildProcess.emit (events.js:182:13)
    at ChildProcess.EventEmitter.emit (domain.js:442:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)

原因

new cdk.CfnOutput(scope, 'hoge', { value: 'hoge' }); と第一パラメータをscope としてたのですが、this じゃないとだめでした・・・圧倒的・・・ケアレスミス・・・

lib/cdk-error-test-stack.ts
import cdk = require('@aws-cdk/core');

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

    new cdk.CfnOutput(this, 'hoge', { value: 'hoge' });
  }
}

tsファイルを修正後npm run build コマンドを実行しないとさらにハマりますのでご注意ください。

> npm run build


> cdk synth -v
(略)
Outputs:
  hoge:
    Value: hoge
Resources:
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Modules: aws-cdk=1.2.0,@aws-cdk/core=1.2.0,@aws-cdk/cx-api=1.2.0,jsii-runtime=node.js/v10.11.0

constructorsuper のパラメータ指定に引きづられて気がつくのに相当時間がかかりました。
エラーメッセージからだとさっぱりみえてこなかったので、皆さまお気をつけください。

参考

AWS CDK - неопределенная ошибка при создании службы AWS ECS - amazon-web-services | Qaru
http://qaru.site/questions/17927695/aws-cdk-vague-error-while-creating-an-aws-ecs-service

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?