Configuring DB connectors - DynamoDB

Studio enables you to use the database connectors to connect to your NoSQL databases like CouchDB, MongoDB, DynamoDB and so on.

DynamoDB is a key-value and document database that delivers single-digit millisecond performance at any scale.

Configuring DynamoDB connector

To add a DB connector, under Studio > Connectors, click (+) Connector and select DynamoDB connector.

You need to first configure the database. Enter the Connector name which would be used when you need the connector in your apps and while adding queries.

Get AWS Credentials

First, create a new user and enable “Programmatic access” to the user, and set the permissions.

You need to get the AWS Access Key and AWS Secret Key and also make sure that you store it safely for future reference. If you are unable to find them, then you can create a new pair of keys via the AWS console under the My Security Credentials section of the AWS console in the top-right corner of your screen.

  • Click AWS Console > My Security Credentials > Access Keys > Create New Access Key

After you have the Security Credentials, you can then configure the Connector.

For the DynamoDB database you need to provide the following:

  • AWS Region
  • AWS Access Key ID
  • AWS Secret Key
  • User Role : User role is optional
  • Whitelist IP

Once these configurations are added, click Test Connection. If the authentication is successful you would get the response accordingly. Click Save to Finish configuration.

Adding queries to the Database connector

Now that you have configured the connector you will find it under the Connectors list. Now to fetch data or undertake any other action, click the Add query option available once your connection is ready.

You can provide a name to the query using Enter a Service name. Add your query and click Run or press Ctrl + enter to run the query. The rows returned from the collection are shown in the Response section.

You can also add dynamic values using the Variables. To add the variable, click Variables > +Add. Add the FieldName and select the Field type. Add a Test Value to check the results before saving. You can also add a Default value or make it Mandatory. Add the Help text that would be shown with the field. You can also add any preset formula. Once you have entered the details, click Add Variable. The variable would be listed under Variables. You can make use of the variable in the query where you created the variable.

To use a variable inside a query, you simply need to put it into double Curly brackets. The Test value that you entered would be considered for fetching data. When using the connector queries the dynamic variables would have to be linked to the respective control for further run time functioning.

You can now view the queries that you saved for using in your apps later under your specific connector under Custom Database connectors.

Using DynamoDB connector

Scan all documents

Now let us take a simple example to scan a Dynamodb collection and get all rows from the collection and display them in a tablegrid control. In this case you simply need to select the collection, select the type of action as Query as per the DynamoDB syntax.

Add the query as seen above and run to verify the output. Once done Save the query.

Now under Bind Data you can use this query to get data. Add a tablegrid control and configure the Connector.

Select the necessary keys to get the data.

So now when you take a preview of the respective form you would be able to see the data accordingly.

Find data

In this case you simply need to select the collection, select the type of action as Query as per the DynamoDB syntax. Here you can also provide the Key Condition Expression, Filter, and Projection expression. If no Attributes names are provided you would get all the attributes. However, if you want to retrieve a specific item then you need to add it as the Projection Expression.

You can add the dynamic variable to pass it to a query as an expression. Remember that you would have to follow the syntax that is as per the DynamoDB syntax which you can refer to from this link here. In this example here we are sending the ID as a dynamic variable. So you would be getting that ID from the user to display Data. The control would be passed as a parameter to the query when configuring your connector.

Now when you run the query you would get the data for the respective ID that is passed to the database.

Insert data

Using the DB Connector for DynamoDB is similar to using it with other databases. You can make use of the Queries to fetch data as well bind data such that you can undertake the insert, update, delete actions as well.

Now if you want to insert data to your table you can use the Insert Query for the same with the respective values for the same. You can fetch it from your form and assign the respective values using the dynamic variables.

In this example, you would be accepting the data from a form and adding it on the Click of your Action button. Hence you will configure the Connector from the Action Flow > Server Side actions and add the respective controls as Keywords.

So whenever you run your form and click to submit data, the action flow would be triggered and the Connector will enable you to add data to your DynamoDB database.

Update Data

You can also update data from the collection using the Update action. Here you can also provide the Key Condition Expression, Filter, and Projection expression. If no Attributes names are provided you would get all the attributes. However, if you want to update a specific item then you need to add it as the Projection Expression.

You can have a scenario like say choosing an ID from a drop-down and entering the data to update.

updatescreen

Delete data

Similarly, if you want to delete data from your database you would have to choose Action as deleteItem and provide the key to delete the item using the dynamic variable.

Then you simply need to configure your connection and pass the selected ID from the tablegrid and trigger the action to delete the record.

It could be any scenario like say choosing a record from your table grid control and fetching the ID and adding the action flow to delete a record.