Serverless.yml DynamoDB 错误 ValidationException:提供的项目键列表包含重复项

Serverless.yml DynamoDB Error ValidationException: Provided list of item keys contains duplicates

我的 serverless.yml 配置文件中不断出现以下错误。 “无服务器:DynamoDB - 创建了 table 个事务

验证异常 ----------------------------------

ValidationException:提供的项键列表包含重复项 “ 可能是什么问题呢? 这是整个 .yml 文件。 谢谢...!


service: dynamo
useDotenv: true
configValidationMode: error
frameworkVersion: ^2.52.0

provider:
  name: aws
  runtime: nodejs12.x
  stage: dev
  region: us-east-1
  lambdaHashingVersion: 20201221

custom:
  dynamodb:
    stages:
      - dev
    start:
      port: 8000
      inMemory: true
      heapInitial: 200m
      heapMax: 1g
      migrate: true
      seed: true
      convertEmptyValues: true
    seed:
      dev:
        sources:
          - table: transactions
            sources: [./txs.json]
  
functions:
  app:
    handler: index.handler
    events:
      - http:
          path: transactions
          method: get
  UI:
    handler: index.handler
    events:
      - http: 
          path: UI
          method: get

resources:
  Resources:
    transactionsTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: transactions
        AttributeDefinitions:
          - AttributeName: country
            AttributeType: S
          - AttributeName: createdAt
            AttributeType: N
        KeySchema:
          - AttributeName: country
            KeyType: HASH  
          - AttributeName: createdAt
            KeyType: RANGE
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        GlobalSecondaryIndexes:
          - IndexName: country_created_at_index
            KeySchema:
              - AttributeName: country
                KeyType: HASH
              - AttributeName: createdAt
                KeyType: RANGE
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1

plugins:
  - serverless-dynamodb-local
  - serverless-offline
  - serverless-bundle

你的GlobalSecondaryIndexes完全相同的键是你的主要table。您需要不同的密钥对。否则 GlobalSecondaryIndexes.

没有意义

已修复: 玩弄 LocalSecondaryIndexes,直到我这样做了。

service: dynamo
useDotenv: true
configValidationMode: error
frameworkVersion: ^2.52.0

provider:
  name: aws
  runtime: nodejs12.x
  stage: dev
  region: us-east-1
  lambdaHashingVersion: 20201221

custom:
  dynamodb:
    stages:
      - dev
    start:
      port: 8000
      inMemory: true
      heapInitial: 200m
      heapMax: 1g
      migrate: true
      seed: true
      convertEmptyValues: true
    seed:
      dev:
        sources:
          - table: transactions
            sources: [./txs.json]
  
functions:
  app:
    handler: index.handler
    events:
      - http:
          path: transactions/
          method: get
  ui:
    handler: index.handler
    events:
      - http: 
          path: ui/
          method: get

resources:
  Resources:
    transactionsTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: transactions
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: country
            AttributeType: S
          - AttributeName: createdAt
            AttributeType: N
        KeySchema:
          - AttributeName: id
            KeyType: HASH  
          - AttributeName: createdAt
            KeyType: RANGE
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        LocalSecondaryIndexes:
        - IndexName: id_index
          KeySchema: 
          - AttributeName: id
            KeyType: HASH
          - AttributeName: country
            KeyType: RANGE
          Projection: 
            ProjectionType: ALL
        GlobalSecondaryIndexes:
          - IndexName: country_created_at_index
            KeySchema:
              - AttributeName: country
                KeyType: HASH
              - AttributeName: createdAt
                KeyType: RANGE
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1

plugins:
  - serverless-dynamodb-local
  - serverless-offline
  - serverless-bundle