Skip to content

Changing DynamoDB from Provisioned to On Demand via CDK process?

0

Hello, I'm trying to change my DynamoDB table from Provisioned to On Demand via CDK.

The commented out code is what my table was provisioned with before, for autoscaling.

table = new TableV2(this, props.tableName, {
                partitionKey: { name: props.partitionId, type: AttributeType.STRING },
                sortKey: { name: props.sortId!, type: AttributeType.STRING },
                removalPolicy: cdk.RemovalPolicy.DESTROY,
                // billing: Billing.provisioned({
                //     readCapacity: Capacity.autoscaled({maxCapacity: 25600 }),
                //     writeCapacity: Capacity.autoscaled({ maxCapacity: 1600 })
                // }),
                // warmThroughput: {
                //     readUnitsPerSecond: 25600,
                //     writeUnitsPerSecond: 6400
                // },
                billing: Billing.onDemand({
                    maxReadRequestUnits: 25600,
                    maxWriteRequestUnits: 6400
                }),
                dynamoStream: StreamViewType.NEW_AND_OLD_IMAGES
              });

When attempting to deploy, I run into this issue: 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. How do I actually specify these values for the autoscaled resources?

2 Answers
0

You must make CDK aware of seedCapacity before making the change:

https://github.com/aws/aws-cdk/issues/27735

    table = new TableV2(this, props.tableName, {
      partitionKey: { name: props.partitionId, type: AttributeType.STRING },
      sortKey: { name: props.sortId!, type: AttributeType.STRING },
      removalPolicy: cdk.RemovalPolicy.DESTROY,
      billing: Billing.provisioned({
          readCapacity: Capacity.autoscaled({maxCapacity: 25600, seedCapacity: 25600 }),
          writeCapacity: Capacity.autoscaled({ maxCapacity: 1600, seedCapacity: 1600})
      }),
      // warmThroughput: {
      //     readUnitsPerSecond: 25600,
      //     writeUnitsPerSecond: 6400
      // },
      // billing: Billing.onDemand({
      //   maxReadRequestUnits: 25600,
      //   maxWriteRequestUnits: 6400
      // }),
      dynamoStream: StreamViewType.NEW_AND_OLD_IMAGES
    });

Then when you deploy, it will have knowledge of the capacity to set in-case of roll-back. Then deploy to on-demand:

    table = new TableV2(this, props.tableName, {
      partitionKey: { name: props.partitionId, type: AttributeType.STRING },
      sortKey: { name: props.sortId!, type: AttributeType.STRING },
      removalPolicy: cdk.RemovalPolicy.DESTROY,
      warmThroughput: {
          readUnitsPerSecond: 25600,
          writeUnitsPerSecond: 6400
      },
      billing: Billing.onDemand({
        maxReadRequestUnits: 25600,
        maxWriteRequestUnits: 6400
      }),
      dynamoStream: StreamViewType.NEW_AND_OLD_IMAGES
    });

Also, you should be aware that warmThroughput and maxRead/WriteRequestUnits do no serve the same purpose.

AWS
EXPERT

answered a year ago

-2

When switching a DynamoDB table from provisioned capacity mode with autoscaling to on-demand mode using CDK, you need to specify a seedCapacity for each autoscaled resource. This is required so that CloudFormation can properly roll back if needed.

To fix your issue, you should modify your code to include the seedCapacity parameter in your on-demand configuration:

table = new TableV2(this, props.tableName, {
partitionKey: { name: props.partitionId, type: AttributeType.STRING },
sortKey: { name: props.sortId!, type: AttributeType.STRING },
removalPolicy: cdk.RemovalPolicy.DESTROY,
billing: Billing.onDemand({
maxReadRequestUnits: 25600,
maxWriteRequestUnits: 6400,
seedCapacity: {
readCapacityUnits: 5,  // Set an appropriate seed value
writeCapacityUnits: 5  // Set an appropriate seed value
}
}),
dynamoStream: StreamViewType.NEW_AND_OLD_IMAGES
});

The seedCapacity parameter is crucial when changing from provisioned to on-demand mode or vice versa. It provides CloudFormation with the necessary information to handle the transition between capacity modes and ensures that if a rollback is needed, it has the appropriate capacity values to revert to.

When switching from provisioned to on-demand mode, it's also worth noting that:

  1. If you were using the console previously, auto scaling settings would be deleted
  2. If using CDK/CloudFormation, your previous auto scaling settings need to be preserved through the seedCapacity parameter
  3. The table will continue to deliver throughput consistent with the previously provisioned capacity during the transition
    Sources
    aws-cdk-lib.aws_dynamodb module · AWS CDK
    Considerations when switching capacity modes in DynamoDB - Amazon DynamoDB

answered a year ago

  • This is actively wrong as seedCapacity parameter does not exist on DynamoDB TableV2 class.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.