【问题标题】:How to set DynamoDB Read/write capacity mode to On-demand on CloudFormation如何在 CloudFormation 上将 DynamoDB 读/写容量模式设置为按需
【发布时间】:2019-05-08 05:13:28
【问题描述】:

我在site 上看到了有关 DynamoDB On-demand 的信息,我将由 CloudFormation 创建的表更新为 On-demand。现在,当我尝试更新我的堆栈时,我收到了这个错误:

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

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

编辑:

我已在 AWS 控制台上更新为按需。

编辑 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

谢谢。

【问题讨论】:

  • 根据错误,您似乎几乎在做您想做的事,但您未能清除旧的 RCU 设置。您的 CFN 模板的这一部分是什么样的?
  • 模板是这样的:`ProvisionedThroughput: ReadCapacityUnits: 2 WriteCapacityUnits: 2`。另外,我尝试将 0 替换为 2 并删除 ProvisionedThroughput。
  • 删除ProvisionedThroughput 是正确的,根据docs。此外,您还需要删除任何自动缩放。删除 ProvisionedThroughput 有什么错误?它应该与问题中的不同。
  • @Michael-sqlbot 在没有按需的表中,当我删除 ProvisionedThroughput 时出现此错误:> 内部故障
  • 我认为 AWS 团队正在更新 CloudFormation。添加BillingMode 时出现此错误:“遇到不支持的属性BillingMode”。我会等下几天再试。谢谢@Michael-sqlbot

标签: amazon-web-services amazon-dynamodb amazon-cloudformation


【解决方案1】:

您需要将BillingMode: PAY_PER_REQUEST 添加到属性并从表属性和所有GlobalSecondaryIndexes(如果指定)中删除ProvisionedThroughput。所以最后你的模板必须看起来像:

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

【讨论】:

  • 谢谢,康斯坦丁。此外,请确保删除二级索引的预置吞吐量而不将其替换为 BillingMode,否则您将收到错误“遇到不支持的属性 BillingMode”。
  • @Konstantin Labun 知道如何有条件地完成吗?所以我的开发和测试环境的吞吐量为 1,但对于 beta 和 prod,我需要它是 PAY_PER_REQUEST,我该如何实现?
猜你喜欢
  • 2023-02-02
  • 2022-01-25
  • 1970-01-01
  • 2019-07-08
  • 2021-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多