Integrating MuleSoft with AWS Dynamo DB

To know more on DynamoDB and how to run it locally, check the below post

Running AWS DynamoDB in your local workspace
How to run AWS Dynamo DB on local workspace?
  1. The Book Id is set to UUID

2. We then need to transform the input payload to something that Dynamo DB can recognize

%dw 2.0output application/json---{	book_id: {		S: vars.bookId	},	book_name: {		S: payload.bookName	},	book_price: {		S: payload.bookPrice	},	book_author: {		S: payload.bookAuthor	},	book_categories:{		l: payload.bookCategories map ((item, index) ->{			S: item		})	},	is_book_available:{		bool: payload.isAvaiable	}}

Here S represents String, l represents List and bool represents Boolean.

So, we need to transform incoming payload to the above structure to make it DynamoDB specific payload.

3. We use the Configuration created earlier and use the payload created above to insert data.

4. Finally we can return the UUID to client for reference in the last Transform Message.

%dw 2.0output application/json---{	status: "Success",	message: "Data inserted successfully",	bookId: vars.bookId}

  • Fetch Book Flow
  1. This private flow takes book_id and return the book details from Table

We use Get item operation to fetch the details.

We pass id from query parameters as a string input and fetch the details.

2. The final transformation is then created to transform DynamoDB specific payload to user readable payload

%dw 2.0output application/json---{	bookName: payload.item.book_name.s,	bookPrice: payload.item.book_price.s,	bookAuthor: payload.item.book_author.s,	bookCategories: payload.item.book_categories.l map ((item, position) -> 		(item.s)	),	isAvailbale: payload.item.is_book_available.bool}


Let’s try this now!

We pass input payload for Book with details and it responds us with a bookId

We then use the given bookId to fetch book details


Hope you liked it. Cheersâś”

 

Leave a Reply

Your email address will not be published. Required fields are marked *