Using AWS Lambda as a Microservice

In this article, we are going to discuss about How we can use AWS Lambda as a Microservice when developing Serverless E-Commerce application.

Serverless Event-driven E-commerce Microservices Architecture

At the end of the article we will be design the Reference Architecture above which is a Real-world Serverless E-commerce application.

Step by Step Design AWS Architectures w/ Course

I have just published a new course — AWS Serverless Microservices with Patterns & Best Practices.

In this course, we’re going to learn how to Design and Develop AWS Serverless Event-driven Microservices with using AWS Lambda, AWS DynamoDB, AWS API Gateway, AWS EventBridge, AWS SQS, AWS CDK for IaCInfrastructure as Code tool and AWS CloudWatch for monitoring.

Source Code

Get the Source Code from Serverless Microservices GitHub — Clone or fork this repository, if you like don’t forget the star. If you find or ask anything you can directly open issue on repository.

AWS as an Application Development Framework

As you know that, in the previous article, we understood that why AWS Serverless can be use as a Application Development Framework.

Evolution of AWS Infrastructure

So AWS Lambda is a core key service of AWS Serverless landscape. For that reason, we will put AWS Lambda in the middle of our architecture and design our Serverless E-commerce Microservices with using AWS Lambda.

Before we start, let’s remember What are Microservices ?

What are Microservices ?

Microservice are small business services that can work together and can be deployed autonomously / independently.

These services communicate with each other by talking over the network and bring many advantages with them. One of the biggest advantages is that they can be deployed independently. Also, it offers the opportunity to work with many different technologies.

https://github.com/aspnetrun/run-aspnetcore-microservices

So we can say that, Microservices;

  • have their own technology stack, included the database and data management model;
  • communicate to each other over a combination of REST APIs, event streaming, and message brokers;
  • are organized by business capability, with the line separating services often referred to as a bounded context.

When it comes to AWS Lambda, AWS Lambda is using for greater agility. It is clear that microservices can help companies be more agile and develop software faster.
So where does AWS Lambda come into the equation?

AWS Lambda as a Microservice

AWS Lambda is a service that allows you to run your functions in the cloud completely Serverless and eliminates the operational complexity. You upload your code to Lambda, and it takes care of everything needed to run and scale its execution and fulfill conditions and high availability requirements. Lambda supports several programming languages so you can choose the most suitable.
It integrates with the API gateway, allows you to invoke functions with the API calls, and makes your architecture completely Serverless. There are several ways to invoke a function: an event, another AWS service, or another service or application.

https://docs.aws.amazon.com/whitepapers/latest/microservices-on-aws/serverless-microservices.html

So can we put AWS Lambda as a microservice in our Serverless E-Commerce application.

You can see the figure above that shows the architecture of a Serverless microservice with AWS Lambda, where the entire service is built from managed services, which removing the architectural overhead of designing for scaling and high availability, and eliminating the operational efforts of operating and monitoring the microservice’s underlying infrastructure.

Serverless Microservices with Lambda

In microservices architecture, each of the application components is decoupled and deployed and run independently. An API created with Amazon API Gateway, and then AWS Lambda-initiated functions is all you need to build a microservice. Your team can use these services to decouple and segment your environment to the desired level of detail.

In general, a microservices environment can introduce the following difficulties:

  • repeated overhead for create each new microservice,
  • problems optimizing server density and usage,
  • complexity of running multiple versions of multiple microservices at the same time,
  • and client-side code requirements to integrate with many services.

When you create microservices using Serverless resources, these problems become less difficult to resolve and, in some cases, simply disappear.

https://docs.aws.amazon.com/whitepapers/latest/microservices-on-aws/serverless-microservices.html

The Serverless Microservices Pattern reduces the barrier for the creation of each subsequent microservice. API Gateway even allows for the cloning of existing APIs, and using of Lambda functions in other accounts.
Optimizing server utilization is no longer relevant with this pattern. Finally, Amazon API Gateway provides programmatically generated client SDKs that are programmatically built in a number of popular languages in order to reduce the integration overhead.

You can see the figure above that shows the architecture of a Serverless microservice with Amazon API Gateway and AWS Lambda. So API Gateway APIs proxy to individual microservices backed by Lambda functions. You can see the microservices-1–2–3–4 that proxy by API Gateway and all of microservices handle with AWS Lambda functions.

So now we are ready to develop our enterprise E-Commerce application with fully Serverless Event-driven Microservices Architecture using AWS Lambda as a Microservices.

AWS Serverless Microservices for Ecommerce Application Architecture

Here you can find the main overall Serverless Architecture for our application. This is the big picture of what we are going to develop together for AWS Serverless Event-driven E-commerce Microservices application that is Step by Step Implementation together.

Serverless Event-driven E-commerce Microservices Architecture

We will be following the reference architecture above which is a real-world Serverless E-commerce application and it includes;

  • REST API and CRUD endpoints with using AWS Lambda, API Gateway
  • Data persistence with using AWS DynamoDB
  • Decouple microservices with events using AWS EventBridge
  • Message Queues for cross-service communication using AWS SQS
  • Cloud stack development with IaC using AWS CloudFormation CDK

Step by Step Design AWS Architectures w/ Course

I have just published a new course — AWS Serverless Microservices with Patterns & Best Practices.

In this course, we’re going to learn how to Design and Develop AWS Serverless Event-driven Microservices with using AWS Lambda, AWS DynamoDB, AWS API Gateway, AWS EventBridge, AWS SQS, AWS CDK for IaCInfrastructure as Code tool and AWS CloudWatch for monitoring.

Source Code

Get the Source Code from Serverless Microservices GitHub — Clone or fork this repository, if you like don’t forget the star. If you find or ask anything you can directly open issue on repository.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store