Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 394
Pedro Arantes Avatar asked Dec 06 '18 13:12

Pedro Arantes


People also ask

How does DynamoDB determine read and write capacity?

If you need to write an item that is larger than 1 KB, DynamoDB must consume additional write capacity units. Transactional write requests require 2 write capacity units to perform one write per second for items up to 1 KB. The total number of write capacity units required depends on the item size.

When using provisioned capacity mode How are you charged for Amazon DynamoDB?

When you purchase reserved capacity, you must designate an AWS Region, quantity, and term. You will be charged (1) a one-time upfront fee, and (2) an hourly fee for each hour during the term based on the amount of DynamoDB reserved capacity you purchase.

What is capacity modes in DynamoDB?

There are two selectable capacity modes in DynamoDB: Provisioned and On-Demand. While On-demand is perfect for unpredictable workloads with sudden spikes of traffic, the provisioned mode is cheaper and better suited for workloads with predictable traffic.


1 Answers

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 
like image 69
Konstantin Labun Avatar answered Sep 23 '22 01:09

Konstantin Labun