DynamoDB Integration

Querying Amazon DynamoDB with Retool.

DynamoDB is Amazon's non-relational managed database. Retool connects with DynamoDB, allowing you to access your data from your internal tools.

Connecting DynamoDB

First, go to IAM and create a new user called retool-dynamodb. Only enable "programmatic access".

Click "next" to grant the account permissions. It's easiest to grant the account full DynamoDB permissions, but you can restrict permissions further. You'll need to create a new policy and attach this policy to the user. Here's an example JSON IAM policy, which you can modify to your security needs.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "VisualEditor0",
      "Effect": "Allow",
      "Action": [
        "dynamodb:ListTables",
        "dynamodb:DeleteItem",
        "dynamodb:ListTagsOfResource",
        "dynamodb:DescribeReservedCapacityOfferings",
        "dynamodb:DescribeTable",
        "dynamodb:GetItem",
        "dynamodb:DescribeContinuousBackups",
        "dynamodb:DescribeLimits",
        "dynamodb:BatchGetItem",
        "dynamodb:BatchWriteItem",
        "dynamodb:PutItem",
        "dynamodb:ListBackups",
        "dynamodb:Scan",
        "dynamodb:Query",
        "dynamodb:DescribeStream",
        "dynamodb:UpdateItem",
        "dynamodb:DescribeTimeToLive",
        "dynamodb:ListStreams",
        "dynamodb:DescribeGlobalTableSettings",
        "dynamodb:ListGlobalTables",
        "dynamodb:GetShardIterator",
        "dynamodb:DescribeGlobalTable",
        "dynamodb:DescribeReservedCapacity",
        "dynamodb:DescribeBackup",
        "dynamodb:GetRecords"
      ],
      "Resource": "*"
    }
  ]
}

Once you've created the user, head back to Retool. To connect to DynamoDB, you will need your AWS Access Key, Secret Key, and the region of your DynamoDB instance. Go to Resources, click Add, and select DynamoDB from the options.

Configuration screen for DynamoDB.Configuration screen for DynamoDB.

After picking the region and filling out your credentials, press Save to test the connection. Now your resource will be available for queries.

Query DynamoDB

You can now select your new DynamoDB resource from the Resource dropdown when creating queries in your Retool apps.

You can write DynamoDB queries using the default GUI mode and entering values into the provided input fields. If you need greater flexibility, you can enable the JSON parameter editor to construct queries using JSON. This is useful if you need to copy queries from existing Node projects or would like to dynamically generate query JSON based on other Retool properties.

Query syntax

The DynamoDB query editor is powered by DynamoDB's document client. The document client interface makes it easier for JavaScript apps to interact with DynamoDB by abstracting away the notion of attribute values and using native JavaScript types. The following examples demonstrate how to interact with DynamoDB using the AWS CLI and what the same interaction looks like on Retool.

PutItem operation

New items are added to a DynamoDB collection using the putItem operation. This is performed with the AWS CLI using put-item.

aws dynamodb put-item \
    --table-name Music \
    --item '{ "Artist": {"S": "Acme Band"}, "SongTitle":  {"S": "Happy Day"}, "AlbumTitle": {
"S": "Songs About Life"}, "Awards": {"N": "10"} }'

Using retool's DynamoDB query editor, you specify the table, the putItem method, and include necessary parameter values.

DynamoDB putItem queryDynamoDB putItem query

If you are using the JSON parameter editor, you would provide much of this information as JSON.

{ 
  "TableName": "Music",
  "Item": {
    "Artist": "Acme Band", 
    "SongTitle": "Happy Day", 
    "AlbumTitle": "Songs About Life", 
    "Awards": 10 
 }
}

Query operation

You use the query operation to look up and filter items in a DynamoDB collection. This is performed with the AWS CLI using query.

aws dynamodb query \
   --table-name Music \
   --key-condition-expression "Artist = :name" \
   --expression-attribute-values  '{ ":name": { "S":"Acme Band"}}'

Using retool's DynamoDB query editor, you specify the table, the query method, and include necessary parameter and expression values.

Query a DynamoDB collectionQuery a DynamoDB collection

As before, you would provide much of this information as JSON if you are using the JSON parameter editor.

{ 
  "TableName": "Music",
  "KeyConditionExpression":  "#artist = :artist",
  "ExpressionAttributeNames": { "#artist" : "Artist" },
  "ExpressionAttributeValues": {":artist": "Acme Band"}
}

Queries using the query or scan methods return the array of results within the queryName.data.Items key.

Refer to the AWS DynamoDB documentation for more information on querying DynamoDB.

Example: How to build a DynamoDB admin panel

In this video, you'll find a 15 minute walk through on how to build an admin panel connected to a DynamoDB instance.

We cover implementing create, read, update and delete functionality in the app.


Did this page help you?