Search code examples
amazon-web-servicesamazon-dynamodbaws-cloudformationserverlessdynamodb-queries

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


I Keep getting the following error on my serverless.yml configurations file. "Serverless: DynamoDB - created table transactions

Validation Exception ------------------------------------

ValidationException: Provided list of item keys contains duplicates " What could be the problem? Here’s the entire .yml file. Thanks…!


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


Solution

  • Your GlobalSecondaryIndexes has exactly same keys are your main table. You need different key pairs. Otherwise there is no point for GlobalSecondaryIndexes.