Skip to content

Latest commit

 

History

History
110 lines (82 loc) · 4.39 KB

querying-dynamodb.md

File metadata and controls

110 lines (82 loc) · 4.39 KB

DynamoDB

{% hint style="warning" %} The following document assumes that you understand the basics of connecting to databases on Appsmith. If not, please go over them before reading further. {% endhint %}

Connection Settings

Appsmith needs the following parameters for connecting to a DynamoDB instance:

Click to expand

{% hint style="success" %} All required fields are suffixed with an asterisk (*). {% endhint %}

  • Region*: Select the region where your DynamoDB instance exists
  • Host Address / Port*: Fill in the database host’s address and port. You only need to fill these fields in case you wish to override the default endpoint chosen by AWS
  • AWS Access Key Id*: The identifier for your AWS Access key that is configured to have access to this database
  • AWS Secret Access Key*: The secret key for this identifier

All the above three details can be fetched from your AWS account:

  1. How to get AWS access key?
  2. How to get AWS secret key?
  3. AWS DynamoDB regions/endpoints

Querying DynamoDB

DynamoDB databases can be queried using any of the operations that are officially supported. The request body expects a JSON object that represents a map of parameters to query the database. Here we have listed some of the most basic operations to get started with using a DynamoDB API.

ListTables

The ListTables command can be used to retrieve all the tables available at the current endpoint. This request can be run without a body.

DescribeTable

The DescribeTable command returns metadata about the table that is queried using the JSON body. A sample request might have the following body:

{
    "TableName" : "four"
}

GetItem

The GetItem command retrieves a single item on the basis of its primary key. This primary key can be configured in any of DynamoDB's supported types for attribute values. The request would use this specified type in the JSON body. In the following example, the primary key is called "pkey" and is of type String or S and hase a value of a.

{
    "TableName" : "four",
    "Key": {
        "pkey" : {
            "S" : "a"
        }
    }
}

PutItem

The PutItem command is used to insert or replace an entire item object. This request can be configured to return with the inserted/updated item using the ReturnValues parameter. Here, we use the PutItem command for a simple insert.

{
    "TableName" : "four",
    "Item" : {
        "pkey" : {
            "S" : "a"
        },
        "name": {
            "S" : "Irene"
        },
        "friends": {
            "SS" : ["Sherlock"]
        }
    }
}

UpdateItem

The UpdateItem can be used for conditionally updating parts of an item. This request also supports ReturnValues as well as new inserts.

{
    "TableName" : "four",
    "Key" : {
        "pkey" : {
            "S" : "a"
        }
    },
    "UpdateExpression" : "set friends = :new_friends",
    "ExpressionAttributeValues" : {
        ":new_friends" : {
            "SS" : ["Mycroft", "Watson", "Irene"]
        }
    },
    "ReturnValues" : "ALL_NEW"
}

Using Queries in applications

Once you have successfully run a Query, you can use it in your application to