Scanning and Creating a Table in DynamoDB Using MuleSoft Connector

DZone 's Guide to

Scanning and Creating a Table in DynamoDB Using MuleSoft Connector

Let's see how to scan and create a table in DynamoDB.

· Database Zone ·
Free Resource

Image title

Creating a table in DynamoDB

Amazon DynamoDB is a fully managed NoSQL database service. While doing a recent project, I found that there was very little documentation about using the Mulesoft DynamoDB connector. In this article, I will share my experience of using the Mule DynamdDB connector so that it can help others. Please feel free to add your comments.

You might also enjoy: Working With DynamoDB

The Anypoint Connector for Amazon DynamoDB provides connectivity to the Amazon DynamoDB API, enabling you to interact with Amazon DynamoDB to create a database table that can store and retrieve any amount of data, serve any level of request traffic, and automatically spread the data and traffic for the table over a sufficient number of servers to handle the request capacity and the amount of data stored, while maintaining consistent and fast performance.

The DynamoDB connector can be downloaded from Anypoint Exchange in Anypoint Studio.

The scan operation returns the data from DynamoDB in a Java object, which is not in a readable format. So, we need to transform the data according to our requirements.

The data can be retrieved for all attributes or from specific attributes. This can be selected in Scan operation.

To connect DynamoDB, we need to pass Access Key ID, Secret Access Key in DynamoDB connector as shown in the below screen.

Image title

We can test if the connection is successful or not by clicking the test connection button. Once the connection is successful, click the ok button.

After redirecting to the parent screen, the user needs to provide the table name from where the values need to be scanned, like below:

Image title

The options available in the Select drop-down are ALL_ATTRIBUTES, COUNT, SPECIFIC_ATTRIBUTES, and ALL_PROJECTED_ATTRIBUTES.

  • ALL_ATTRIBUTES will scan all rows and columns and display.

  • COUNT will scan for no.of records available in the table.

  • SPECIFIC_ATTRIBUTES will scan for those attributes only which you specify in the attribute names.

  • ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an Index Name.

Creating a Table in Dynamo DB

To create a table in Dynamo DB, we need to select the createTable operation in the flow.

Image title

Once the Test Connection is successful, click the OK button.

On the parent window, define the table name and attributes (column names) like below:

Image title

Also add ‘Key Schema’, which specifies the attributes that make up the primary key of the table like below. You can also add Read Capacity Units (The maximum number of strongly consistent reads per second) and Write Capacity Units (The maximum number of writes consumed per second).

Image title

Add a transformer to your flow, else the response will be downloaded as an encoded text file, which is very difficult to understand. The transformer is like below:

Image title

The XML snippet of this is:

<dynamodb:create-table readCapacityUnits="10" writeCapacityUnits="10" doc:name="Create table" config-ref="Amazon_DynamoDB_Configuration" tableName="Employee">
    <dynamodb:attribute-definitions >
        <dynamodb:attribute-definition attributeName="Id" attributeType="NUMBER" />
    <dynamodb:key-schemas >
        <dynamodb:key-schema-element attributeName="Id" keyType="HASH" />
<ee:transform doc:name="Transform Message" doc:id="e73052fb-b2ab-49d0-af87-0d75f59f5f47" >
    <ee:message >
        <ee:set-payload >
            <![CDATA[%dw 2.0
output application/JSON


The table will be updated successfully.

Further Reading

Getting Started With DynamoDB and Spring

An Introduction to DynamoDB Injection

amazon dynamodb ,dynamodb ,integration ,mule 4 ,mule connectors ,mulesoft anypoint connector ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}