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

问题描述 投票:0回答:1

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

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的关键。

amazon-web-services amazon-dynamodb
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.