Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway DynamoDB GetItem without sort key?

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"
}

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!

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

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

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

like image 842
Garvit Jain Avatar asked May 30 '18 07:05

Garvit Jain


1 Answers

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

Query API

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.

like image 185
notionquest Avatar answered Sep 22 '22 18:09

notionquest