You cannot. DynamoDB requires that all attributes you are filtering for have an index.

As you want to query independently of your main index, you are limited to Global Secondary Indexes.

The documentation lists on what kind of attributes indexes are supported:

The index key attributes can consist of any top-level String, Number, or Binary attributes from the base table; other scalar types, document types, and set types are not allowed.

Your type would be an array of Strings. So this query operation isn't supported by DynamoDB at this time.

You might want to consider other NoSQL document based databases which are more flexible like MongoDB Atlas, if you need this kind of querying functionality.

Answer from Udo Held on Stack Overflow
🌐
DynamoDB
dynobase.dev › code-examples › dynamodb-query-json
[Code Examples] DynamoDB: Query JSON
But you can use the query operation to get data as an array and pass the result to JSON.stringify method to convert the array to a JSON string. const AWS = require('aws-sdk'); const dynamoDb = new AWS.DynamoDB.DocumentClient(); const params = { TableName: 'tableName', KeyConditionExpression: 'primaryKey = :primaryKeyValue', ExpressionAttributeValues: { ':primaryKeyValue': 'value' } }; dynamoDb.query(params, (error, data) => { if (error) { console.error(error); return; } console.log(JSON.stringify(data.Items)); });
Discussions

dynamodb complex json search
What is the proper way to return data with HTTP API + Lambda + DynamoDB as a json response? More on repost.aws
🌐 repost.aws
1
0
September 7, 2023
[HELP] DynamoDB Console Query -> JSON Query
Have you looked at the DynamoDB marshaller? I'm not sure I understand your question but it might be what you need. More on reddit.com
🌐 r/aws
2
4
August 3, 2017
amazon web services - How to simplify aws DynamoDB query JSON output from the command line? - Stack Overflow
I'm working with The AWS Command Line Interface for DynamoDB. When we query an item, we get a very detailed JSON output. You get something like this (it has been built from the get-item in order t... More on stackoverflow.com
🌐 stackoverflow.com
java - DynamoDB query on sub field of JSON Object - Stack Overflow
Originally in this table ... and then query with the json string as a key.. Now we need to implement searching by sub fields of that object, which can contain different fields each time, i.e. isDigital: "true". I notice in the question: DynamoDB advanced scan ... More on stackoverflow.com
🌐 stackoverflow.com
June 7, 2016
🌐
AWS
aws.amazon.com › blogs › database › working-with-json-data-in-amazon-dynamodb
Working with JSON data in Amazon DynamoDB | Amazon Web Services
May 1, 2023 - In this post, we explore some of ... do with JSON objects in DynamoDB. You can install DynamoDB shell (ddbsh) for Mac using homebrew, and for Ubuntu using pre-built binaries that are available on github. Refer to the “Using prebuilt binaries” section. We use DynamoDB shell (ddbsh) to illustrate these capabilities. To learn more, refer to Query data with ...
🌐
Reddit
reddit.com › r/aws › [help] dynamodb console query -> json query
r/aws on Reddit: [HELP] DynamoDB Console Query -> JSON Query
August 3, 2017 -

When I craft a query with the AWS DynamoDB Console, I want to capture the equivalent JSON query. Like how I can use Postman's Builder to craft a REST query and the "Code" button will show me the equivalent cURL, nodejs, etc.

I'm using nodejs and the aws-sdk module. So ideally, the resulting JSON query will be suitable for AWS.DynamoDB, AWS.DynamoDB.DocumentClient, or both.

Any ideas? Thank you!

🌐
Coderanch
coderanch.com › t › 737837 › databases › query-JSON-DynamoDb-storing-JSON
If one cannot query from inside the JSON using DynamoDb then what is the use of storing JSON docs? (Other Big Data forum at Coderanch)
December 29, 2020 - In that case what is the use of storing the JSON docs?. DynamoDb despite being a document oriented store does not support such queries.
🌐
BMC Software
bmc.com › blogs › dynamodb-queries
How To Query Amazon DynamoDB – BMC Software | Blogs
July 23, 2020 - The query is below. We use backslashes (\) after each line because that’s the continuation character in the bash shell. And we put a single quote (‘) around JSON for the same reason, so that it can span lines. ... aws dynamodb query \ --endpoint-url http://localhost:8000 \ --table-name Movies \ --key-condition-expression "#yr = :yyyy" \ --expression-attribute-names '{"#yr": "year"}' \ --expression-attribute-values '{ ":yyyy":{"N":"2010"}}'
Find elsewhere
🌐
AWS
docs.aws.amazon.com › amazon dynamodb › api reference › actions › amazon dynamodb › query
Query - Amazon DynamoDB
For more information, see Query and Scan in the Amazon DynamoDB Developer Guide. ... Valid Range: Minimum value of 1. ... A string that identifies one or more attributes to retrieve from the table. These attributes can include scalars, sets, or elements of a JSON document.
🌐
Medium
elvisciotti.medium.com › export-dynamodb-data-into-json-format-and-run-stats-with-jq-ca6ab8f51590
Export DynamoDB data into JSON format and run stats with JQ | by Elvis Ciotti | Medium
October 25, 2023 - So I can now query with jq e.g. echo "Group by of userIds:" cat dynamo.backup.slurp.json | jq 'group_by(.userId.S) | map({userId: .[0].userId.S, count: length}) | sort_by(-.count)' | head -n 50 echo "Number of elements:" cat dynamo.backup.slurp.json | jq 'length' echo "Unique users:" cat dynamo.backup.slurp.json | jq 'map(.userId.S) | unique | length'
🌐
Medium
medium.com › @NotSoCoolCoder › handling-json-data-for-dynamodb-using-python-6bbd19ee884e
Handling JSON data for DynamoDB using Python | by NotSoCoolCoder | Medium
July 23, 2022 - Once the data would be added to database, I would be able to query the data at ‘sibling’ level. Here is how this will be stored to database. ... Look at the data stored in database. It’s JSON, isn’t it? However, there is a difference between what we have as input and what is there in database now. The different is not at ‘data’ level, but DynamoDB needs to know DataType associated with data.
🌐
Talend
help.talend.com › talend components › amazon dynamodb › amazon dynamodb scenario › writing and extracting json documents from dynamodb › extracting a json document using advanced filters
Extracting a JSON document using advanced filters | Talend Components Help
February 21, 2024 - In the Table Name field, enter the name of the DynamoDB table to be created by tDynamoDBOutput. Select the Use filter expression check box and then the Use advanced filter expression check box. In the Advanced filter expression field, enter the filter to be used to select JSON documents.
🌐
AWS re:Post
repost.aws › knowledge-center › appsync-nested-json-data-in-dynamodb
Configure AWS AppSync to handle JSON data in DynamoDB | AWS re:Post
October 7, 2022 - For Region, choose the Region that contains your DynamoDB table. For Table name, choose the table you just created. Important: Leave all other options as default. ... For more information, see Attaching a data source. ... 3. Copy and paste the following nested JSON schema into the JSON editor, and then choose Save Schema: Important: Make sure that you overwrite the prefilled content in the JSON editor with the nested JSON schema. ... type Query { getItems(id: String!): allData } type allData { id: String!
🌐
Tibco
integration.cloud.tibco.com › docs › Subsystems › flogo-amazondynamodb › users-guide › amazon-dynamodb-query.html
Amazon DynamoDB Query
The Amazon DynamoDB Query activity allows you to execute a query on DynamoDB database. ... The Input tab contains the input schema. The fields that were selected on the Input Settings tab are available in the schema. You can either hard code their values or map them to a field from the output ...
🌐
AWS
aws.amazon.com › blogs › aws › dynamodb-update-improved-json-editing-key-condition-expressions
DynamoDB Update – Improved JSON Editing & Key Condition Expressions | Amazon Web Services
November 3, 2022 - We have made some improvements to DynamoDB in order to make it more powerful and easier to use. Here’s what’s new: You can now add, edit, and retrieve native JSON documents in the AWS Management Console. You can now use a friendly key condition expression to filter the data returned from a query ...
🌐
Stack Overflow
stackoverflow.com › q › 49655955
Dealing with JSON data returned from a DynamoDB query
The query above returns: 16:44:45: PnKVrm12 undefined · I expected it to return: 16:44:45: PnKVrm12 Tech Lab · for some reason I can never access data in either temperature or sensor_name. I would appreciate some advice if you have time. javascript · json · react-native · amazon-dynamodb ·
🌐
Coderanch
coderanch.com › t › 737835 › databases › query-DynamoDb-parameter-field-JSON
How to query in DynamoDb using a parameter which is a field inside JSON? (Other Big Data forum at Coderanch)
December 29, 2020 - I created a DynamoDb table ProductCatalog. Next, I created a item with id (primary key) as 1, title as 'Book 210 Title' and vendorInfo as the below JSON: This constitutes one item. I did a scan on the table which displayed the item. Next, I did a query by specifying id as 1, it returned the item as result.
Top answer
1 of 6
27

You can decode the values recursively with a well crafted function. It looks like the key names correspond to a type:

S -> string
N -> number
M -> map

Handle each of the cases you want to decode if possible, otherwise filter it out. You can make use of the various type filters and the alternative operator to do so.

$ cat input.json
{
  "Count": 1,
  "Items": [
    {
      "Id": { "S": "app1" },
      "Parameters": {
        "M": {
          "nfs#IP": { "S": "192.17.0.13" },
          "maxCount": { "N": "1" },
          "nfs#defaultPath": { "S": "/mnt/ebs/" }
        }
      }
    }
  ],
  "ScannedCount": 1,
  "ConsumedCapacity": null
}
$ cat ~/.jq
def decode_ddb:
    def _sprop($key): select(keys == [$key])[$key];                 # single property objects only
       ((objects | { value: _sprop("S") })                          # string (from string)
    // (objects | { value: _sprop("NULL") | null })                 # null (from boolean)
    // (objects | { value: _sprop("B") })                           # blob (from string)
    // (objects | { value: _sprop("N") | tonumber })                # number (from string)
    // (objects | { value: _sprop("BOOL") })                        # boolean (from boolean)
    // (objects | { value: _sprop("M") | map_values(decode_ddb) })  # map (from object)
    // (objects | { value: _sprop("L") | map(decode_ddb) })         # list (from encoded array)
    // (objects | { value: _sprop("SS") })                          # string set (from string array)
    // (objects | { value: _sprop("NS") | map(tonumber) })          # number set (from string array)
    // (objects | { value: _sprop("BS") })                          # blob set (from string array)
    // (objects | { value: map_values(decode_ddb) })                # all other non-conforming objects
    // (arrays | { value: map(decode_ddb) })                        # all other non-conforming arrays
    // { value: . }).value                                          # everything else
    ;
$ jq 'decode_ddb' input.json
{
  "Count": 1,
  "Items": [
    {
      "Id": "app1",
      "Parameters": {
        "nfs#IP": "192.17.0.13",
        "maxCount": 1,
        "nfs#defaultPath": "/mnt/ebs/"
      }
    }
  ],
  "ScannedCount": 1,
  "ConsumedCapacity": null
}
2 of 6
3

Another way to achieve the post's goal would be to use a node.js extension like node-dynamodb or dynamodb-marshaler and build a node command line tool.

Interesting tutorial to build a node.js command line application with commander package: Creating Your First Node.js Command-line Application


Here's a quick and dirty oneliner that reads one record from stdin and prints it in simplified form:

node -e 'console.log(JSON.stringify(require("aws-sdk").DynamoDB.Converter.unmarshall(JSON.parse(require("fs").readFileSync(0, "utf-8")))))'
🌐
Styra
docs.styra.com › tutorials › using data › querying dynamodb
Querying DynamoDB with dynamodb.get and dynamodb.query | Enterprise OPA | Styra Documentation
Enterprise OPA provides the dynamodb.get and dynamodb.query built-in functions for querying DynamoDB during policy evaluation.
🌐
Tibco
docs.tibco.com › pub › flogo-amazondynamodb › 1.0.1 › doc › html › GUID-7F6E18B2-6B5A-4A84-9F4C-8E94D058CE1B.html
Amazon DynamoDB Query
TIBCO Flogo® Connector for Amazon DynamoDB · Home · ... The Configuration tab has the following field. This tab has the following fields: The Input tab contains the input schema. The fields that were selected on the Input Settings tab are available in the schema.