DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Production Database Migration or Modernization: A Comprehensive Planning Guide [Part 2]
  • The Bill You Didn't See Coming
  • How Online Databases Replicate Public Records: A Look at Data Aggregation
  • Migration from Lovable Cloud to Supabase

Trending

  • Java String Format Examples
  • Evolving Spring Boot APIs to an Event-Driven Mesh
  • Agentic AI Design Patterns and Principles: Building Autonomous, Collaborative Systems
  • AWS Kiro: The Agentic IDE That Makes Specs the Unit of Work
  1. DZone
  2. Data Engineering
  3. Data
  4. How To Insert, Retrieve, and Query Data From Amazon Dynamo DB in Mule 4

How To Insert, Retrieve, and Query Data From Amazon Dynamo DB in Mule 4

In this article, I'm going to share a step-by-step guide to store data in Dynamo DB and retrieve data based on various conditions in mule 4.

By 
Kunal Thakur user avatar
Kunal Thakur
·
Dec. 25, 21 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
13.0K Views

Join the DZone community and get the full member experience.

Join For Free

Mulesoft - Amazon DynamoDB Connector 

Anypoint Connector for Amazon DynamoDB (Amazon DynamoDB Connector), as the name goes, provides connectivity to the Amazon DynamoDB API. 

Amazon DynamoDB is a fully managed NoSQL database service. It enables fast performance and seamless scalability. The role of Amazon DynamoDB Connector is to ensure interaction with Amazon DynamoDB in order to store and retrieve data from Dynamo DB.

Prerequisites

To be able to use the Amazon DynamoDB connector, we need to have the following:

  • An AWS account with accessibility to the Amazon DynamoDB.
  • AWS Identity and Access Management (IAM) credentials including access and secret keys.

Demo Application

We have to follow the following steps:

  1. Create DynamoDB Table - Employees with partition key as 'EmployeeId' and sort key as 'Email'.
  2. Convert input data to DynamoDB JSON format and insert data into DB using a put-item connector.
  3. Retrieve data from DB using a get-item connector.
  4. Query data from DB based on the partition key.
  5. Query data from DB based on sort key or any other attribute of the table. 

We are using an HTTP listener to invoke functionalities like Inserting and retrieving messages from the DB. We are further using the Put Item, Get-Item, and Query connector. Below are the steps in detail:

Step 1: Create Dynamo DB Table

  • Log in to AWS Console and go to the DynamoDB section.
  • Click on Tables on the left-hand side.
  • Click on create table and create a new table - 'Employees' with partition key as 'EmployeeId' and sort key as 'Email'.

Step 2: Convert Input Data to DynamoDB JSON Format and Insert Data into DB Using Put Item Connector


Convert input data to DynamoDB JSON

Input data:

Input data

Request JSON payload has attributes with String and Boolean datatype, also it contains an array.

DB Request Transform:

DB request to transform data

Add Employee Configuration:

Adding employee configuration

Adding employee configuration

Make sure that the test connection is successful. Once data is inserted, this is how it looks like on the AWS Dynamo DB console:

AWS Dynamo DB console

Step 3: Retrieve Data From DB Using the Get-Item Connector.


Retrieving data from DB through Get-Item connector

Key variable - set the key to retrieve data from DB:

Setting key variable to retrieve data

If partition key and sort key exists for a table in Dynamo DB then we have to provide both keys in order to retrieve data from Dynamo DB if we are using the Get-Item connector to retrieve the data.

Retrieve Employee:

Setting a display name

Transform DB Response:

We've to extract the data from the response received from the DB as below:

Transforming DB response

Step 4: Query Data from DB Based on the Partition Key

Querying data from DB

Key variable - set the key to retrieve data from DB:

Setting key variable to retrieve data

If we have to retrieve data based on partition key or sort key only then we've to query it from DB based on these keys. 

Query:

We've to provide key variables in the Query Parameters section and provide filter conditions in key condition expressions.

Provide key variables in the Query Parameters section

We are retrieving based on 'EmployeeId' which is a partition key.

Transform DB Response: 

We've to extract the data from the response received from the DB as below:

Transforming DB response

Step 5: Query Data From Db Based on Sort Key or Any Other Attribute of the Table

Global Secondary Index(GSI)

  • In order to query based on a field other than partition key, we've to first create a global secondary index on that table in Dynamo DB.
  • Here we've created a GSI 'Email-index' to retrieve data based on sort-key 'Email', keeping 'Email' as partition key for this GSI.

Key variable - Query:

We've to provide key variables in the Query Parameters section and provide filter conditions in key condition expression.  Also, we've to provide a global secondary index name in the config as below:

Providing key variables in the Query Parameters section

We are retrieving data based on 'Email' which is a sort key. Similarly, we can query based on any other field on the table.

Transform DB Response: 

We've to extract the data from the response received from the DB as mentioned in step-4.

And that's all! Now you know how to store data in Dynamo DB and retrieve data based on various conditions in mule 4. 

Data (computing) Database DYNAMO (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Production Database Migration or Modernization: A Comprehensive Planning Guide [Part 2]
  • The Bill You Didn't See Coming
  • How Online Databases Replicate Public Records: A Look at Data Aggregation
  • Migration from Lovable Cloud to Supabase

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook