How to set DynamoDB Read/write capacity mode to On-demand on CloudFormation

Pedro Arantes picture Pedro Arantes · Dec 6, 2018 · Viewed 8.5k times · Source

I've seen this site about DynamoDB On-demand and I updated my tables, created by CloudFormation, to On-demand. Now, when I try to update my Stack, I get this error:

One or more parameter values were invalid: Neither ReadCapacityUnits nor WriteCapacityUnits can be specified when BillingMode is PAY_PER_REQUEST

Is there a way to set DynamoDB Read/write capacity mode to On-demand on CloudFormation?

EDIT:

I've updated to On-demand on AWS Console.

EDIT 2:

My template:

DynamoDBUsersTable:
    Type: AWS::DynamoDB::Table
    Description: Users table
    Properties:
      TableName: !Sub ${StackName}-users-table
      AttributeDefinitions:
        - AttributeName: userId
          AttributeType: S
      KeySchema:
        - AttributeName: userId
          KeyType: HASH
      ProvisionedThroughput:
        ReadCapacityUnits: 10
        WriteCapacityUnits: 10

Thank you.

Answer

Konstantin Labun picture Konstantin Labun · Dec 30, 2018

You need to add BillingMode: PAY_PER_REQUEST to properties and remove ProvisionedThroughput both from table properties and from all GlobalSecondaryIndexes if they specified. So finally your template have to look like:

DynamoDBUsersTable:
    Type: AWS::DynamoDB::Table
    Description: Users table
    Properties:
      TableName: !Sub ${StackName}-users-table
      BillingMode: PAY_PER_REQUEST
      AttributeDefinitions:
        - AttributeName: userId
          AttributeType: S
      KeySchema:
        - AttributeName: userId
          KeyType: HASH