首页 > 解决方案 > serverless-dynamodb-local 没有迁移新的全局二级索引

问题描述

我正在使用serverless-offline和开发 AppSync + DynamoDB serverless-dynamodb-local。我添加了新的全局二级索引并使用以下命令进行迁移。

$ serverless dynamodb migrate

接下来,我开始使用以下命令进行本地调试。

$ sls offline start

我查询但失败了。

{
    "version" : "2017-02-28",
    "operation" : "Query",
    "index" : "groupId-index",
    "query" : {
        "expression": "groupId = :groupId",
        "expressionValues" : {
            ":groupId" : $util.dynamodb.toDynamoDBJson($ctx.args.groupId)
        }
    }
}
Error while executing Local DynamoDB
{
    "version": "2017-02-28",
    "operation": "Query",
    "index": "groupId-index",
    "query": {
        "expression": "groupId = :groupId",
        "expressionValues": {
            ":groupId": {
                "S": "group-001"
            }
        }
    }
}
ValidationException: The table does not have the specified index: groupId-index

我的 dynamodb 表定义serverless.yml

UserTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: UserTable
        KeySchema:
          -
            AttributeName: id
            KeyType: HASH
        AttributeDefinitions:
          -
            AttributeName: id
            AttributeType: S
          -
            AttributeName: groupId
            AttributeType: S
        BillingMode: PAY_PER_REQUEST

        GlobalSecondaryIndexes:
          -
            IndexName: groupId-index
            KeySchema:
              - AttributeName: groupId
                KeyType: HASH
            Projection:
              ProjectionType: ALL

我的 serverless-dynamodb-local 配置是

dynamodb:
    stages:
      - dev
    start:
      port: 8000
      inMemory: true
      migrate: true
      seed: true
    seed:
      dev:
        sources:
          - table: UserTable
            sources: [./migrations/user.json]
          - table: ChatMessageTable
            sources: [./migrations/chatMessage.json]

我应该怎么办?我在没有本地测试和从 appsync 控制台查询的情况下部署并成功。所以我认为配置文件是有效的。

编辑1:这是我的serverless start offline日志。

Dynamodb Local Started, Visit: http://localhost:8000/shell
Serverless: DynamoDB - Warn - table UserTable already exists
Serverless: DynamoDB - Warn - table ChatMessageTable already exists
Seed running complete for table: UserTable
Seed running complete for table: ChatMessageTable

我删除.dynamodb文件夹和serverless dynamodb install. 但是出现了同样的消息。

标签: amazon-web-servicesamazon-dynamodbserverless

解决方案


推荐阅读