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

12,685

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
Share:
12,685

Related videos on Youtube

Pedro Arantes
Author by

Pedro Arantes

There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. — C.A.R. Hoare

Updated on June 04, 2022

Comments

  • Pedro Arantes
    Pedro Arantes about 2 years

    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.

    • Michael - sqlbot
      Michael - sqlbot over 5 years
      Removing ProvisionedThroughput is correct, according to docs. Also you'd need to have removed any auto-scaling. What is the error with ProvisionedThroughput removed? It should be different than the one in the question.
    • Pedro Arantes
      Pedro Arantes over 5 years
      I think the AWS team is updating CloudFormation. I had this error when I added BillingMode: "Encountered unsupported property BillingMode". I'll wait and try again next days. Thank you @Michael-sqlbot
  • Wojciech K
    Wojciech K over 5 years
    Thanks, Konstantin. Additionally, make sure to delete the provisioned throughput of secondary indexes without replacing it with BillingMode, otherwise you will get the error 'Encountered unsupported property BillingMode'.
  • Affan Shahab
    Affan Shahab almost 5 years
    @Konstantin Labun Any idea how can it be done conditionally? So my dev and test env has throughput as 1 but for beta and prod I need it to be PAY_PER_REQUEST, how can I achieve that?
  • Konstantin Labun
    Konstantin Labun almost 5 years
    You can do it using cloudformation conditions docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/…