无法在 DynamoDB 中创建计费模式设置为 PAY_PER_REQUEST 的表

Kha*_*Jan 2 amazon-dynamodb aws-cli

我目前正在使用 AWS cli 在 DynamoDB 中创建一个表。我正在使用的命令是

aws dynamodb create-table --cli-input-json file://.feature_promotions-dynamodb.json  --endpoint-url http://localhost:8000
Run Code Online (Sandbox Code Playgroud)

根据 的文档create-table,我应该能够将计费模式设置为,而PAY_PER_REQUEST不必设置预配置的吞吐量,但每次运行命令时我都会收到以下错误:

An error occurred (ValidationException) when calling the CreateTable operation: No provisioned throughput specified for the table
Run Code Online (Sandbox Code Playgroud)

awscli昨天升级到

aws-cli/1.16.90 Python/3.7.2 Darwin/18.2.0 botocore/1.12.80
Run Code Online (Sandbox Code Playgroud)

除此之外,我不知道如何解决它。目前我的解决方法是仅创建具有预配置吞吐量的表,然后转到控制台进行更改,但这似乎没有必要。最终,我希望能够在 bash 脚本中运行此命令,而不必稍后修复 AWS 控制台中的表设置。

下面是我在命令中加载的 JSON 文件create-table"BillingMode": "PAY_PER_REQUEST"属性和值是在之后设置的"AttributeDefinition",我希望它能够正常工作而不会出现任何错误。如果我删除计费模式行,并将以下属性添加到文件中

"ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      }
Run Code Online (Sandbox Code Playgroud)

它创建的表没有任何错误。

{
  "TableName": "dev.feature_promotions",
  "AttributeDefinitions": [
    {
      "AttributeName": "display_title",
      "AttributeType": "S"
    },
    {
      "AttributeName": "end_date",
      "AttributeType": "N"
    },
    {
      "AttributeName": "id",
      "AttributeType": "N"
    },
    {
      "AttributeName": "partner_id",
      "AttributeType": "N"
    },
    {
      "AttributeName": "start_date",
      "AttributeType": "N"
    },
    {
      "AttributeName": "view_scope_id",
      "AttributeType": "N"
    }
  ],
  "BillingMode": "PAY_PER_REQUEST",
  "KeySchema": [
    {
      "AttributeName": "id",
      "KeyType": "HASH"
    }
  ],
  "GlobalSecondaryIndexes": [
    {
      "IndexName": "start_date-index",
      "KeySchema": [
        {
          "AttributeName": "start_date",
          "KeyType": "HASH"
        },
        {
          "AttributeName": "id",
          "KeyType": "RANGE"
        }
      ],
      "Projection": {
        "ProjectionType": "ALL"
      },
      "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      }
    },
    {
      "IndexName": "display_title-index",
      "KeySchema": [
        {
          "AttributeName": "display_title",
          "KeyType": "HASH"
        },
        {
          "AttributeName": "id",
          "KeyType": "RANGE"
        }
      ],
      "Projection": {
        "ProjectionType": "ALL"
      },
      "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      }
    },
    {
      "IndexName": "end_date-index",
      "KeySchema": [
        {
          "AttributeName": "end_date",
          "KeyType": "HASH"
        },
        {
          "AttributeName": "id",
          "KeyType": "RANGE"
        }
      ],
      "Projection": {
        "ProjectionType": "ALL"
      },
      "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      }
    },
    {
      "IndexName": "partner_id-index",
      "KeySchema": [
        {
          "AttributeName": "partner_id",
          "KeyType": "HASH"
        },
        {
          "AttributeName": "id",
          "KeyType": "RANGE"
        }
      ],
      "Projection": {
        "ProjectionType": "ALL"
      },
      "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      }
    },
    {
      "IndexName": "view_scope_id-index",
      "KeySchema": [
        {
          "AttributeName": "view_scope_id",
          "KeyType": "HASH"
        },
        {
          "AttributeName": "id",
          "KeyType": "RANGE"
        }
      ],
      "Projection": {
        "ProjectionType": "ALL"
      },
      "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      }
    }
  ],
  "StreamSpecification": {
    "StreamEnabled": true,
    "StreamViewType": "NEW_AND_OLD_IMAGES"
  },
  "SSESpecification": {
    "Enabled": true,
    "SSEType": "AES256",
    "KMSMasterKeyId": ""
  }
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

F_S*_*O_K 5

您只能在表或 GSI 上使用"BillingMode": "PAY_PER_REQUEST"其中之一。ProvisionedThroughput您需要删除ProvisionedThroughput任何按需资源。

编辑:要明确的是,您不能使用ProvisionedThroughput按需表的索引。要解决此问题,只需删除 的所有实例即可ProvisionedThroughput。您的索引也将按需提供。