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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • How to Configure AWS Glue Job Using Python-Based AWS CDK
  • Building a Scalable ML Pipeline and API in AWS
  • Build a REST API With Just 2 Classes in Java and Quarkus
  • AWS Cloud Security: Key Components, Common Vulnerabilities, and Best Practices

Trending

  • How to Build Real-Time BI Systems: Architecture, Code, and Best Practices
  • Designing a Java Connector for Software Integrations
  • Mastering Advanced Aggregations in Spark SQL
  • Infrastructure as Code (IaC) Beyond the Basics
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Low Code Approach for Building a Serverless REST API

Low Code Approach for Building a Serverless REST API

In this article, we will build a REST-based service on AWS lambda, API gateway, and PostgreSQL database.

By 
Rohini Arun kumar user avatar
Rohini Arun kumar
·
Apr. 03, 23 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
9.0K Views

Join the DZone community and get the full member experience.

Join For Free

Building REST-based services is pretty common when it comes to the backend world. When it comes to developing the service in a serverless world, it's a trend, but it comes with a lot of pain. For instance, we need to write a function in the language of our choice, then need to build a provisioning script like cloud formation or terraform to chain the set of services used for building the solution. 

In this article, we will be building a REST-based service on AWS lambda, API gateway, and PostgreSQL database. The key part is that we will be developing it completely using a low code integration tooling and runtime framework, Kumologica. 

Use Case

The customer registration portal of enterprise ABC Company requires a backend service to store the data. The portal will invoke the rest-based service to insert the customer information when the customer is registered. The admin page of the portal has features for listing customer records.

High-Level Design

High-Level Design


As per the design given above, the enterprise is using AWS cloud provider and its Lambda service for hosting the backend rest API service. The lambda function will be developed using Kumologica designer and runtime framework, which runs on Node.JS. The lambda function needs to connect with the PostgreSQL database hosted externally as managed service.

Pre-Requisites

1. Having an AWS cloud account with necessary IAM access or user having permissions (As prescribed during Kumologica designer installation).

2. AWS profile configured in your machine.

3. Install Kumologica Designer.

4. Create a Trial account in  ElephantSQL (Managed service of PostgreSQL database).

5. Run the following SQL script to create the customer table.

SQL
 
CREATE TABLE CUSTOMER(
   NAME CHAR(50) PRIMARY KEY      NOT NULL,
   EMAIL           CHAR(50) NOT NULL,
   AGE         INT      NOT NULL,
   ADDRESS           CHAR(50) NOT NULL
);


Implementation

Let's get started implementing the solution by first opening the Kumologica Designer by using the command kl open via terminal or windows command line.

1. Create a new project by providing the Project name and customer service.

2. Install the SQL node in the workspace by opening a command line or terminal and going to the path of your project workspace (location of the project package.json). Enter the following npm command to install.

Plain Text
 
npm i @kumologica/kumologica-contrib-sql


Flow for Listing the Customers

3. Drag and drop the Event Listener node onto the designer canvas and provide the following configuration for the Event Listener node. 

Plain Text
 
Display Name : [GET] /customers
Event Source : Amazon API Gateway
Verb : GET
URL : /customers


The above configuration is for flow that is listing all the customers.

4. Add a logger node from the palette to the canvas and wire the Event listener node to it. Provide the following log message.

 
Display Name : Log_Entry
Level : INFO
Message : Request received
Log format : String


5. From the storage category in the palette, select the SQL node and drop it after the logger node. Provide the following configuration.

 
Display Name : GetCustomers
Provider : Postgres
Host : <<Hostname provided by elephant SQL platform>>
Port : 5432
Database : <<Database name provided by elephant SQL platform>>
Timeout : 10000
Username : <<Username provided by elephant SQL platform>>
Password : <<Password provided by elephant SQL platform>>
Query : SELECT * FROM CUSTOMER;


6. Drag and drop an Eventlistener End node and wire it to the output of the SQL node. Provide the following configuration.

 
Display Name : Success
Response : Http Response
Status code : 200
Header > Content-Type : application/json
Payload : msg.payload.rows


Final flow implementation for customer listing.

Final flow implementation for customer listing.

Flow for Adding Customer

1. Add the EventListner node with the following configuration.

 
Display Name : [POST] /customers
Event Source : Amazon API Gateway
Verb : POST
URL : /customers


2. Add a JSON node and wire it to the EventListner node. Open the node and select "Always convert a JSON string to an object." 

3. Add a logger and provide the following configuration. Wire the logger to the output of the JSON node.

 
Display Name : Log_Entry
Level : INFO
Message : msg.payload
Log format : JSON


4. Add the SQL node and provide the following configuration. Wire the output of the logger to the SQL node.

 
Display Name : AddCustomer
Provider : Postgres
Host : <<Hostname provided by elephant SQL platform>>
Port : 5432
Database : <<Database name provided by elephant SQL platform>>
Timeout : 10000
Username : <<Username provided by elephant SQL platform>>
Password : <<Password provided by elephant SQL platform>>
Query : "INSERT INTO CUSTOMER( NAME, EMAIL , AGE , ADDRESS ) VALUES ('" & msg.payload.name & "','" & msg.payload.email & "'," & msg.payload.age & ",'" & msg.payload.address & "');"


5. Wire an EventListener end node to the output of the SQL node and provide the following configuration.

 
Display Name : Success
Response : Http Response
Status code : 200
Header > Content-Type : application/json
Payload : msg.payload


Final flow implementation for customer listing.

Final flow implementation for customer listing.

Deploying to AWS

1. For deploying to AWS, select the AWS deployment icon from the right-hand side panel of the designer.

2. Select the AWS profile name you have created as part of the pre-requisite.

3. Click Deploy.

After deployment is completed, the complete REST endpoint URL for accessing the service will be displayed in the designer terminal. You can test the endpoint using any REST client of your choice.

Conclusion

When deploying the flow from Kumologica designer, the designer automatically packages the flow as a lambda zip along with the AWS cloud formation script. The script is generated by the deployment segment of the designer. The cloud formation script deploys the flow as a node.js-based AWS function and exposes the function via AWS API Gateway. As you can see, we have developed this serverless REST service with very minimal coding and zero scripting.

I hope you liked this article. Stay tuned for the next tutorial.

API AWS AWS Lambda REST Cloud Framework

Opinions expressed by DZone contributors are their own.

Related

  • How to Configure AWS Glue Job Using Python-Based AWS CDK
  • Building a Scalable ML Pipeline and API in AWS
  • Build a REST API With Just 2 Classes in Java and Quarkus
  • AWS Cloud Security: Key Components, Common Vulnerabilities, and Best Practices

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!