AWS API Gateway DynamoDB GetItem 没有排序键? [英] AWS API Gateway DynamoDB GetItem without sort key?

查看:13
本文介绍了AWS API Gateway DynamoDB GetItem 没有排序键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下内容的 Dynamo Db 表

I've a Dynamo Db table with following

{
  "primary_key": {
    "S": "series"
  },
  "sort_key": {
    "S": "type-of-brokers"
  },
  "title": {
    "S": "Types Of Brokers"
}
,
{
  "primary_key": {
    "S": "series"
  },
  "sort_key": {
    "S": "type-of-brokers-2"
  },
  "title": {
    "S": "Types Of Brokers-2"
}

关注此 我已经实现了 application/json 主体映射模板:

Following this I've implemented application/json body mapping template:

{
    "TableName": "table_name",
    "Key" :{
        "primary_key" :{
            "S": "series"
        },
        "sort_key" : {
            "S": "type-of-brokers"
        }
    }
}

它返回一个匹配主键和排序键的项目!

It returns one item that matched primary and sort key!

现在我想返回所有匹配的 primary_key 项目,即没有 sort_key

Now I want to return all the matched primary_key items i.e. without sort_key

我如何做到这一点?使用 API 网关主体映射模板?

How do I achieve that? with API gateway body mapping template?

另外,api 可以返回普通 json 而不是S"类型,这里指定属性 ,可以通过集成响应中不硬编码来完成

Also, can api return common json rather than "S" kind, here it specify attributes , can it be done by not hard coding in integration response

推荐答案

getitem API 需要哈希和排序键.但是,您可以使用仅带有哈希的 query api.

The getitem API requires both hash and sort key. However, you can use query api with only hash only.

查询API

使用 KeyConditionExpression 参数提供特定值为分区键.查询操作将返回所有具有该分区键值的表或索引中的项目.你可以可选地通过指定 a 来缩小 Query 操作的范围KeyConditionExpression 中的排序键值和比较运算符.到进一步细化查询结果,您可以选择提供过滤器表达式.FilterExpression 确定结果应该返回给您.所有其他结果都是丢弃.

Use the KeyConditionExpression parameter to provide a specific value for the partition key. The Query operation will return all of the items from the table or index with that partition key value. You can optionally narrow the scope of the Query operation by specifying a sort key value and a comparison operator in KeyConditionExpression. To further refine the Query results, you can optionally provide a FilterExpression. A FilterExpression determines which items within the results should be returned to you. All of the other results are discarded.

这篇关于AWS API Gateway DynamoDB GetItem 没有排序键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆