Migrating MuleSoft System API to AWS Lambda (Part 1)
In this article, we will be discussing how to migrate a System API running in MuleSoft to AWS Lambda in a quick and efficient manner with the least effort.
Join the DZone community and get the full member experience.
Join For FreeIn this article, we will be discussing how to migrate a System API running in MuleSoft to AWS Lambda in a quick and efficient manner with the least effort. To start, let's understand what system API is in MuleSoft.
What Is System API?
System APIs provide access to data stored in an organization's central systems of record. They can extract information from essential systems such as ERP, customer, and billing databases, as well as proprietary data repositories.
MuleSoft API Flow To Be Migrated
The MuleSoft system API flow has contact details to create and fetch operations from the MSSQL database.
In the above flow, the resource exposed by the API is:
:System API flow /contact.
- To create contact :
[POST] /contact
- To fetch contact by ID:
[GET] /contact/id
When creating the contact, the following JSON payload is passed as input.
{
"firstname" : "Tom",
"lastname" : "Harris",
"Depname" : "Finance",
"empId" : "38993",
"contact_info": {
"contact_email" : "tom@abccorp.com",
"contact_workphone" : "+04-993992909",
"contact_mobile" : "",
"contact_site" : ""
}
}
The response for this API will be the JSON given below.
{
"contact_firstname" : "",
"contact_id" : "<<New Id generated by system>>"
}
Similarly, when fetching the contact details by ID, the following will be the JSON response.
{
"empId" : "38993",
"contactId" : "5555",
"contact_info": {
"contact_email" : "tom@abccorp.com",
"contact_workphone" : "+04-993992909",
"contact_mobile" : "",
"contact_site" : ""
}
}
Migration Journey
We are migrating the above MuleSoft flow to serverless compute of AWS, which is AWS Lambda. The flow implementation will be developed using Kumologica and will be running on the NodeJS runtime of Lambda.
The following are key areas considered when migrating the flow.
API Kit Router: The API kit router of MuleSoft will route the API flow to the appropriate path of create or fetch operation. We will be using EventListener
node in Kumologica for this purpose.
Dataweave: The dataweave will transform the incoming put JSON to the canonical payload expected inside the flow before sending the database. We will be using datamapper
node in Kumologica to replace it.
DBConnector: MuleSoft flow uses a database connector to connect with the MSSQL database. In Kumologica, we will be using an MSSQL node for this purpose.
Security: MuleSoft API is secured via API gateway using API key-based security. In AWS, this will be done via AWS API Gateway and API key authorizer.
Building the Flow in Kumologica
Open the Kumologica developer studio using the command kl open
If you are not familiar with Kumologica designer you may follow the following steps to
install the designer.
npm install @kumologica/sdk
Ensure your are having node version >= 16.14.0 and npm version 8.3.1
On the canvas, drag and drop the EventListener
node and set the following configuration.
For create contact:
Provider : AWS
Event Source : Amazon API gateway
Verb : POST
URL : /contact
For get contact by Id:
Provider : AWS
Event Source : Amazon API gateway
Verb : GET
URL : /contact/:id
Wire the EventListener
node to datamapper
node and provide the following mapping.
{
"db_fname" : msg.payload.firstname,
"db_lname" : msg.payload.lastname,
"db_dep" : msg.payload.Depname,
"db_empid" : msg.payload.empId,
"info": {
"db_cemail" : msg.payload.contact_email,
"db_cworkphone" : msg.payload.contact_workphone,
"db_cmobile" : msg.payload.contact_mobile,
"db_csite" : msg.payload.contact_site
}
}
Now wire the datamapper
node to the MSSQL connector.
For create contact:
INSERT into CONTACT C_fname, C_lname, C_dep, C_empid, C_email, C_workphone, C_mobile,C_site
VALUES msg.payload.db_fname, msg.payload.db_lname, msg.payload.db_dep, msg.payload.db_empid, msg.payload.db_cemail, msg.payload.db_cworkphone, msg.payload.db_cmobile, msg.payload.db_csite
For get contact by id:
SELECT * FROM CONTACT WHERE C_id = msg.payload.id
The final Kumologica flow will look as follows.
Kumologica flow
We will be discussing the testing and production deployment mechanism of this flow in detail in our next article.
Opinions expressed by DZone contributors are their own.
Comments