如何在CloudFormation上将DynamoDB读/写容量模式设置为按需

Ped*_*tes 13 amazon-web-services aws-cloudformation amazon-dynamodb

我已经看过这个关于DynamoDB On-demand的网站,我将我的表格(由CloudFormation创建)更新为按需.现在,当我尝试更新我的堆栈时,我收到此错误:

一个或多个参数值无效:当BillingMode为PAY_PER_REQUEST时,无法指定ReadCapacityUnits和WriteCapacityUnits

有没有办法在CloudFormation上将DynamoDB读/写容量模式设置为按需?

编辑:

我已在AWS Console上更新为按需.

编辑2:

我的模板:

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
Run Code Online (Sandbox Code Playgroud)

谢谢.

Kon*_*bun 32

您需要添加BillingMode: PAY_PER_REQUEST属性并ProvisionedThroughput从表属性和所有GlobalSecondaryIndexes指定的属性中删除它们.所以最后你的模板看起来像:

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
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,康斯坦丁。此外,请确保删除二级索引的预配置吞吐量,而不用BillingMode替换它,否则,您将收到错误“遇到不受支持的属性BillingMode”。 (4认同)
  • 您可以使用 cloudformation 条件 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-struct.html 来完成此操作 (2认同)