DynamoDBをCDKで構築したときにprovisionedからondemandに変更できない

0

質問

DynamoDBをCDKで構築したときにprovisionedからondemandに変更できないです。以下のようなエラーが出てしまうのですが、どのように対応すれば良いのでしょうか。同じ境遇の方や解決された方がいらっしゃいましたらご教示いただきたいです。 よろしくお願いします。

Invalid request provided: When switching billing mode to OnDemand, the previous template must specify a value for all autoscaled resources, so that Cloudformation can rollback if needed.

機械翻訳

無効なリクエストが提供されました: 請求モードをオンデマンドに切り替える場合、Cloudformation が必要に応じてロールバックできるように、前のテンプレートですべての自動スケーリングされたリソースの値を指定する必要があります。

エラー内容

CDK を実行したときのエラー内容です。

00:00:00 | UPDATE_FAILED        | AWS::DynamoDB::GlobalTable                      | Table4B424B7A
Resource handler returned message: "Invalid request provided: When switching billing mode to OnDemand, the previous template must specify a value for all autoscaled resources, so that Cloudformation can rollback if needed." (RequestToken: 744d72a5-010d-de42-9a96-38a5f47dcc25, HandlerErrorCode: InvalidReque
st)


 ❌  CdkStack failed: Error: The stack named CdkStack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Invalid request provided: When switching billing mode to OnDemand, the previous template must specify a value for all autoscaled resources, so that Cloudformation can rollback if needed." (RequestToken: 744d72a5-010d-de42-9a96-38a5f47dcc25, HandlerErrorCode: InvalidRequest)
    at FullCloudFormationDeployment.monitorDeployment (/Users/aws-cdk/node_modules/aws-cdk/lib/index.js:421:10708)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.deployStack2 [as deployStack] (/Users/aws-cdk/node_modules/aws-cdk/lib/index.js:424:180618)
    at async /Users/aws-cdk/node_modules/aws-cdk/lib/index.js:424:163866

CDK の実装内容

変更前(provisioned で DynamoDB を構築)

import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
// : 省略
    const table = new dynamodb.TableV2(this, 'Table', {
      partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING },
      globalSecondaryIndexes: [
        {
          indexName: 'index',
          partitionKey: { name: 'code', type: dynamodb.AttributeType.STRING },
        },
      ],
      billing: dynamodb.Billing.provisioned({
        readCapacity: dynamodb.Capacity.autoscaled({ minCapacity: 5, maxCapacity: 50, targetUtilizationPercent: 25 }),
        writeCapacity: dynamodb.Capacity.autoscaled({ minCapacity: 1, maxCapacity: 5 }),
      }),
      removalPolicy: cdk.RemovalPolicy.DESTROY,
    });
// : 省略

変更後(onDemand で DynamoDB を構築)

import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
// : 省略
    const table = new dynamodb.TableV2(this, 'Table', {
      partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING },
      globalSecondaryIndexes: [
        {
          indexName: 'index',
          partitionKey: { name: 'code', type: dynamodb.AttributeType.STRING },
        },
      ],
      billing: dynamodb.Billing.onDemand(), // ★★★ 変更箇所
      removalPolicy: cdk.RemovalPolicy.DESTROY,
    });
// : 省略
1 réponse
1
Réponse acceptée

TableV2 is an abstraction for GlobalTable CloudFormation construct. With GlobalTables you must define a value for provisioned capacity for all resources (tables and GSI's) in-case the stack update needs to rollback. In your example, you are missing the provisioned capacity for your GSI.

Defined here as readCapacity and writeCapacity.


「TableV2」は GlobalTable CloudFormation 構造の抽象化です。 GlobalTables では、スタックの更新をロールバックする必要がある場合に備えて、すべてのリソース (テーブルと GSI) のプロビジョニングされた容量の値を定義する必要があります。この例では、GSI にプロビジョニングされた容量が不足しています。

ここ を「readCapacity」および「writeCapacity」として定義します。

profile pictureAWS
EXPERT
répondu il y a 4 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions