当前位置: 首页 > 知识库问答 >
问题:

无服务器定义一个Dynamodb,它具有Global二级索引

班经亘
2023-03-14

无服务器错误------------------------------------------我已经返回并转发了文档。似乎这应该是一件简单的事情,但不明白为什么它不让我

出现错误:文件表-一个或多个参数值无效:某些索引键属性未在属性定义中定义。密钥:[UserId],属性定义:[userId,id](服务:Amazon DynamoDBv2;状态代码:400;错误代码:ValidationExcture;请求ID:K28DP2ST778DAN7CP1MV4BDKM3VV4KQNSO5AEMVJF66Q9ASUAAJG;代理:空)。

    documentsTable:
      Type: AWS::DynamoDB::Table
      Properties:
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: userId
            AttributeType: S
        KeySchema:
          - AttributeName: UserId
            KeyType: HASH
        GlobalSecondaryIndexes:
          - IndexName: userIdIndex
            KeySchema:
              - AttributeName: UserId
                KeyType: HASH
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:custom.env}-${self:custom.prefix}-${self:custom.documentDynamoTable2}

当然,我会有这样一个问题

query(
            {
                TableName: documentTable,
                IndexName: 'userIdIndex',
                KeyConditionExpression: '#userId = :userId',
                ExpressionAttributeValues: {
                    ':userId': aUserId
                },
                ExpressionAttributeNames: {
                    "#userId": "userId"
                },
                Select: 'ALL_ATTRIBUTES',
            }
        ).promise();

错误:

{
    "errorType": "ValidationException",
    "errorMessage": "Query condition missed key schema element: id",
    "code": "ValidationException",
    "message": "Query condition missed key schema element: id",
    "time": "2021-03-03T22:59:22.298Z",
    "requestId": "24B4KVLCT9PTIDPPN06ITUTG0JVV4KQNSO5AEMVJF66Q9ASUAAJG",
    "statusCode": 400,
    "retryable": false,
    "retryDelay": 28.89477589112033,
    "stack": [
        "ValidationException: Query condition missed key schema element: id",
..........
}

共有1个答案

孙莫希
2023-03-14

看起来您正在定义一个名为userId(小写u)的属性,然后引用userId(大写u)。

你想要这个

documentsTable:
      Type: AWS::DynamoDB::Table
      Properties:
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: userId
            AttributeType: S
        KeySchema:
          - AttributeName: userId      // <--- CHANGE HERE
            KeyType: HASH 
        GlobalSecondaryIndexes:
          - IndexName: userIdIndex
            KeySchema:
              - AttributeName: userId  // <--- CHANGE HERE
                KeyType: HASH
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:custom.env}-${self:custom.prefix}-${self:custom.documentDynamoTable2}
 类似资料:
  • awsquiestID(S) ttl(N) createdate(S)(ISO) user_id(S) 消息(S) 我想有一个全局二级索引,这样我就可以查询过滤用户的所有消息,我让他们排序(使用排序键),如https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html 出现错误:EventsTable-属性Attr

  • 问题: 主键为复合哈希范围键的DynamoDB表是唯一的。这是否也延伸到二级指数? 示例: 我有一个带有post_id主键和comment_id范围键的comments DynamoDB表。此外,还有一个带有date-user_id范围键的本地辅助索引。 每个条目都是用户在发布时留下的评论。二级索引的目的是统计在特定的一天,有多少唯一的用户在一个帖子上留下了评论。 条目1:post_id:1 co

  • 我希望使用DynamoDB表来请求我在查询中创建的二级索引。 从现在开始,对于我正在做的一个二级索引: 我会像这样构建我的KeyConditionExpression: 我读了一遍又一遍这份文件,但我不知道怎么做: https://docs.aws.amazon.com/fr_fr/amazondynamodb/latest/gettingstartedguide/GettingStarted.P

  • 我对计划中的应用程序的设计有一点问题,特别是数据库引擎和无服务器/非无服务器。目标是一个通过RESTAPI与数据库对话的Web应用程序。RESTAPI本身实际上只是CRUD操作,因此在我看来,无服务器aproach(AWS Lambda)非常适合。因此,最有效的数据库可能是DynamoDB(NoSQL)。 我熟悉RDBMS,对NoSQL数据库知之甚少。 应用程序的模式尚未完成,应该可以在以后进行扩

  • svnserve,一个自定义的服务器 svnserve是一个轻型的服务器,可以同客户端通过在TCP/IP基础上的自定义有状态协议通讯,客户端通过使用开头为svn://或者svn+ssh://svnserve的URL来访问一个svnserve服务器。这一小节将会解释运行svnserve的不同方式,客户端怎样实现服务器的认证,怎样配置版本库恰当的访问控制。 调用服务器 有许多不同方法运行svnserv

  • 我在Dynamodb中有一个表,我试图通过命名全局二级索引来获取一个项目(使用),但我得到了错误: 我的问题是: 但后来我查看了get文档,它没有属性。所以我想也许我应该命名GSI而不是表名: 但后来我面对: 这意味着不被识别为全局表。所以我的问题是,拥有操作列表: 批量获取 批量写入 createSet 删除 得到 把 查询 扫描 更新 哪些支持GSI和LSI?此外,如果您想使用GSI检索一个特