cdk migrate cannot deal with CDK Stacks

オープン
#458 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
aws, typescript

調査の方向性

まず、デフォルトの cdk init スタックで cdk migrate --from-stack --stack-name AppStack を再現し、両方のバージョン報告モードを含めます。生成された TypeScript と AWS::CDK::Metadata の処理を確認します。移行によって構文的に有効なコードが生成され、CDK パスメタデータが省略され、BootstrapVersion パラメータが含まれなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

bug p1

cdk migrate --from-stack --stack-name AppStack

AppStack is the default stack as created by cdk init

First failure:

 ❌  Migrate failed for `AppStack`: AppStackStack could not be generated because Analytics is not a valid property for resource CDKMetadata of type AWS::CDK::Metadata

Deployed the stack again with --no-version-reporting. Then the migrate command works but generated code contains this (including syntax errors):

import * as cdk from 'aws-cdk-lib';
import * as sns from 'aws-cdk-lib/aws-sns';
import * as sqs from 'aws-cdk-lib/aws-sqs';

export interface AppStackStackProps extends cdk.StackProps {
  /**
   * Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]
   * @default '/cdk-bootstrap/hnb659fds/version'
   */
  readonly bootstrapVersion?: string;
}

export class AppStackStack extends cdk.Stack {
  public constructor(scope: cdk.App, id: string, props: AppStackStackProps = {}) {
    super(scope, id, props);

    // Applying default props
    props = {
      ...props,
      bootstrapVersion: new cdk.CfnParameter(this, 'BootstrapVersion', {
        type: 'AWS::SSM::Parameter::Value<String>',
        default: props.bootstrapVersion?.toString() ?? '/cdk-bootstrap/hnb659fds/version',
        description: 'Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]',
      }).valueAsString,
    };

    // Resources
    const appQueueFd3f4958 = new sqs.CfnQueue(this, 'AppQueueFD3F4958', {
      visibilityTimeout: 300,
    });
    appQueueFd3f4958.cfnOptions.metadata = {
      aws:cdk:path: 'AppStack/AppQueue/Resource',
    };
    appQueueFd3f4958.cfnOptions.deletionPolicy = cdk.CfnDeletionPolicy.DELETE;

    const appTopic115Ea044 = new sns.CfnTopic(this, 'AppTopic115EA044', {
    });
    appTopic115Ea044.cfnOptions.metadata = {
      aws:cdk:path: 'AppStack/AppTopic/Resource',
    };

    const appQueuePolicyBd4f9387 = new sqs.CfnQueuePolicy(this, 'AppQueuePolicyBD4F9387', {
      policyDocument: {
        Statement: [
          {
            Action: 'sqs:SendMessage',
            Condition: {
              ArnEquals: {
                'aws:SourceArn': appTopic115Ea044.ref,
              },
            },
            Effect: 'Allow',
            Principal: {
              Service: 'sns.amazonaws.com',
            },
            Resource: appQueueFd3f4958.attrArn,
          },
        ],
        Version: '2012-10-17',
      },
      queues: [
        appQueueFd3f4958.ref,
      ],
    });
    appQueuePolicyBd4f9387.cfnOptions.metadata = {
      aws:cdk:path: 'AppStack/AppQueue/Policy/Resource',
    };

    const appQueueAppStackAppTopic352A2f0bba0ff351 = new sns.CfnSubscription(this, 'AppQueueAppStackAppTopic352A2F0BBA0FF351', {
      endpoint: appQueueFd3f4958.attrArn,
      protocol: 'sqs',
      topicArn: appTopic115Ea044.ref,
    });
    appQueueAppStackAppTopic352A2f0bba0ff351.cfnOptions.metadata = {
      aws:cdk:path: 'AppStack/AppQueue/AppStackAppTopic352A2F0B/Resource',
    };
    appQueueAppStackAppTopic352A2f0bba0ff351.addDependency(appQueuePolicyBd4f9387);
  }
}

Few things to note here:

A/ the generated code should not have syntax errors
B/ we should skip the CDK path metadata anyway
C/ we should probably not include the BootstrapVersion parameter

主要言語
TypeScript
スター
110
フォーク
138
平均マージ
1日 9時間
マージ済み PR(30日)
55

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

aws/aws-cdk-cli のほかの issue

aws/aws-cdk-cli の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。