通过CloudFormation创建DynamoDB表时属性定义不一致

时间:2019-04-23 16:50:27

标签: amazon-web-services amazon-dynamodb

当我尝试构建以下内容时:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Foobar
Resources:
  FailuresTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: Failures
      AttributeDefinitions:
        -
          AttributeName: failureKey
          AttributeType: S
        -
          AttributeName: status,
          AttributeType: S
      KeySchema:
        -
          AttributeName: failureKey
          KeyType: HASH
      GlobalSecondaryIndexes:
        -
          IndexName: failure-status
          KeySchema:
            - AttributeName: status
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
          ProvisionedThroughput:
            ReadCapacityUnits: 5
            WriteCapacityUnits: 15
      ProvisionedThroughput:
        ReadCapacityUnits: 5
        WriteCapacityUnits: 15

我收到一个错误,“属性AttributeDefinitions与表的KeySchema和辅助索引不一致”。

我定义了两个属性:failureKey和status。第一个是在我桌子的钥匙上。第二个是表中唯一GSI的键。

1 个答案:

答案 0 :(得分:0)

全局二级索引的键架构中的第一个键列必须是哈希类型。

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Foobar
Resources:
  FailuresTable:
    Type: AWS::DynamoDB::Table
    Properties:
      AttributeDefinitions:
        -
          AttributeName: "failureKey"
          AttributeType: "S"
        -
          AttributeName: "status"
          AttributeType: "S"
      KeySchema:
        -
          AttributeName: "failureKey"
          KeyType: "HASH"
      ProvisionedThroughput:
        ReadCapacityUnits: 5
        WriteCapacityUnits: 5
      TableName: "Failures"
      GlobalSecondaryIndexes:
        -
          IndexName: "failure-status"
          KeySchema:
            -
              AttributeName: "status"
              KeyType: "HASH"
          Projection:
            ProjectionType: "ALL"
          ProvisionedThroughput:
            ReadCapacityUnits: 5
            WriteCapacityUnits: 5