无法在DynamoDB中将结算方式设置为PAY_PER_REQUEST的表来创建表

时间:2019-01-30 19:31:40

标签: amazon-dynamodb aws-cli

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

aws dynamodb create-table --cli-input-json file://.feature_promotions-dynamodb.json  --endpoint-url http://localhost:8000

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

An error occurred (ValidationException) when calling the CreateTable operation: No provisioned throughput specified for the table

我昨天将awscli升级到了

aws-cli/1.16.90 Python/3.7.2 Darwin/18.2.0 botocore/1.12.80

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

以下是我在create-table命令中加载的JSON文件。 "BillingMode": "PAY_PER_REQUEST"的属性和值是在"AttributeDefinition"之后设置的,我希望它可以正常工作。如果我删除结算方式行,然后将以下属性添加到文件中

"ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      }

它创建表没有任何错误。

{
  "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": ""
  }
}

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

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

编辑:为清楚起见,您不能在按需表的索引上使用ProvisionedThroughput。要解决此问题,只需删除ProvisionedThroughput的所有实例。您的索引也将随需应变。