Skip to main content

Tips and Tricks for Manually Scaling a Global DynamoDB Table from an AWS Lambda

December 1, 2020


Write an AWS Lambda that manually scales a global DynamoDB table



DynamoDB tables can be set to automatically scale based on load. However, this process can take quite a while. We needed to scale up at a precise time to be ready for large batch loads.

According to the auto scaling guide, DynamoDB auto scaling modifies provisioned throughput settings only when the actual workload stays elevated (or depressed) for a sustained period of several minutes. If you have a batch load that will greatly increase load on the system with no ramp-up time, this will cause early slowdowns. If you have sudden, short-duration spikes of activity, consult the burst capacity guide. If you can wait several minutes for ramp-up, auto-scaling should work fine for your use case.


Scale a single (non-global) table

  • Turn off auto-scaling for the table (Provisioned)
  • Use the DynamoDB SDK v1
  • Explicitly call the SDK to set the Read Capacity Units (RCU) and Write Capacity Units (WCU) on the table
  • Initialize configuration
private ClientConfiguration clientConfiguration() {
    final ClientConfiguration clientConfiguration = new ClientConfiguration();
    // These constants are typically environment variables specific to your environment
    // Note: proxy host and port are required in SDK v1
    return clientConfiguration;

private AmazonDynamoDB getClient() {
    // SDK v1 uses the AmazonDynamoDBClientBuilder (v2 does not)
    return AmazonDynamoDBClientBuilder.standard()
// The RCU/WCU can be set directly in this case
ProvisionedThroughput table_throughput = new ProvisionedThroughput(
      read_capacity, write_capacity);

try {
    // Update the DynamoDB table with the ProvisionedThroughput
    getClient().updateTable(table_name, table_throughput);
} catch (AmazonServiceException e) {

Full Version

Scale a global table

  • In this example, the primary table is in us-east-1. A global table was created with a replica in us-west-2
  • Global tables must use auto-scaling
  • Setting the RCU/WCU explicitly on an auto-scaled table does not actually change the RCU/WCU (approach for MVP will not work)
  • Upgrade to SDK v2 to simplify setting the auto-scaling parameters (Note: SDK v2 is quite different from v1 but has simplified the API for DynamoDB manipulation)
  • Set the minimum RCU/WCU on the auto-scaler instead
  • Initialize client
private DynamoDbClient getClient() {
    // These constants are typically environment variables specific to your environment
    ApacheHttpClient.Builder httpClientBuilder = ApacheHttpClient.builder()
    RetryPolicy.Builder retryBuilder = RetryPolicy.builder()
    ClientOverrideConfiguration.Builder clientOverrideBuilder =

    // New DynamoDbClient.builder() for SDK v2
    return DynamoDbClient.builder()
// A series of updates are required to change the auto scaling settings
AutoScalingTargetTrackingScalingPolicyConfigurationUpdate policyConfigurationUpdate =
AutoScalingPolicyUpdate policyUpdate = AutoScalingPolicyUpdate.builder()
// The maximum auto scale capacity is not really used here and can be set to an arbitrarily high number
AutoScalingSettingsUpdate.Builder updateBuilder = AutoScalingSettingsUpdate.builder()

// The minimum units are changed to force a manual scale up/down
AutoScalingSettingsUpdate rcuUpdate = updateBuilder.minimumUnits(HIGH_READ_CAPACITY_UNITS).build();
AutoScalingSettingsUpdate wcuUpdate = updateBuilder.minimumUnits(HIGH_WRITE_CAPACITY_UNITS).build();

// The read capacity units must be updated for each replica
ReplicaAutoScalingUpdate eastReplicaUpdate = ReplicaAutoScalingUpdate.builder()
ReplicaAutoScalingUpdate westReplicaUpdate = ReplicaAutoScalingUpdate.builder()
// The write capacity units impact all replicas
UpdateTableReplicaAutoScalingRequest autoScalingRequest = UpdateTableReplicaAutoScalingRequest.builder()
        .replicaUpdates(eastReplicaUpdate, westReplicaUpdate)

try {
} catch (AmazonServiceException e) {


The code above worked great until the Lambda was deployed in us-west-2 for redundancy. The SDK calls from us-west-2 were timing out.

  • For testing purposes, no SDK v2 calls worked but v1 calls did
  • The solution is to initialize the SDK v1 and then make the SDK v2 calls
  • Add a call to getTable(TABLE_NAME) from the SDK v1 before the call to updateTableReplicaAutoScaling
  • Note: SDK v1 needs the proxy specified but SDK v2 does not
  • Timeouts for the SDK v2 calls may need to be increased from us-west-2


These issues may have been specific to my particular environment. If you experience similar issues, this should help you resolve them. If you have found a solution to the us-west-2 problem, please reach out!

Post by Dennis Sharpe
Dec 1, 2020 8:03:00 AM


©Copyright 2024 Ippon USA. All Rights Reserved.   |   Terms and Conditions   |   Privacy Policy   |   Website by Skol Marketing