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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • A Practical Pipeline for Identifying Sensitive Columns Before Test Data Masking
  • Parquet vs Lance: How Storage Layout Changes the Read Path
  • Production Database Migration or Modernization: A Comprehensive Planning Guide [Part 2]
  • The Bill You Didn't See Coming

Trending

  • Pitching Kotlin: An Engineering Leader's Guide to Legacy Modernization
  • Genkit Flows on Kubernetes, Routed by a Decision Model: senro + jev in Go
  • How You Clear Your HTML5 Canvas Matters
  • Managing Technical Debt in AI-Generated Code

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Dec. 25, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
13.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • A Practical Pipeline for Identifying Sensitive Columns Before Test Data Masking
  • Parquet vs Lance: How Storage Layout Changes the Read Path
  • Production Database Migration or Modernization: A Comprehensive Planning Guide [Part 2]
  • The Bill You Didn't See Coming

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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