AWS Lambda Function Development with other AWS Serverless Services in Real-World Hands-on Labs

In this article, we will learn AWS Lambda Function Developments with using other AWS Serverless Services; Amazon API Gateway, Amazon DynamoDB, Amazon Cognito, Amazon S3, Amazon SNS, Amazon SQS, Amazon EventBridge, AWS Step Functions, DynamoDB and Kinesis Streams and AWS CDK for IaC — Infrastructure as Code tool and AWS CloudWatch for monitoring.

Hands-on Lab: Fan-Out Serverless Architectures Using SNS, SQS and Lambda

So we will learn almost all main AWS Serverless services when developing with AWS Lambda function codes. We will be developing a real-world application with hands-on labs together and step by step.

I have just published a new course — AWS Lambda & Serverless — Developer Guide with Hands-on Labs.

If we summarize and grouping how we can organize all these aws services, you can find captions below:

Basics — Serverless Compute, APIs and Data Persistences

  • AWS Lambda — Serverless, Event-driven Compute Service
  • Amazon API Gateway — API-Driven Development for Synchronous Event
  • Amazon DynamoDB — Data persistence with NoSQL Serverless Database
Organize of AWS Serverless Services that interact with AWS Lambda

Authentication

  • Amazon Cognito — Authentication and Authorization in Serverless

Storing & Hosting

  • Amazon S3 — for Cloud Object Storage in order to store any type of data or deploy our web applications.

AWS Lambda Event-Driven Architectures and Invocation Types

  • AWS Lambda Best Practices and Event-driven Architecture
  • AWS Lambda — Asynchronous invocation
  • AWS Lambda — Lambda event source mappings

Application Integrations Services; Asynchronous Event Sources — Event-based Architectures

  • Amazon SNS — Fully managed pub/sub messaging
  • Amazon SQS — Fully managed message queues — Message Queues for cross-service communication using (AWS SQS)
  • Amazon EventBridge — Decouple microservices with event-driven approaches

Application Orchestration Services

  • AWS Step Functions — orchestrate microservices into Serverless workflows.

SAGA Pattern and apply SAGA pattern with different approaches;

  • Choreography-based SAGA with using Amazon EventBridge — which means Decouple microservices with events
  • Orchestration-based SAGA with using AWS Step Functions — which means Decouple microservices with orchestration way

Streams and Polling Event Source mapping

  • Amazon DynamoDB streams
  • Amazon Kinesis Data streams

Serverless Deployment Frameworks

  • CloudFormation — Speed up cloud provisioning with infrastructure as code
  • AWS CDK — AWS Serverless Deployments IaC with AWS CDK (Cloud Development Kit)

After learning to topics of developing AWS Serverless services with AWS Lambda, we can explore hands-on labs that we will develop.

Real-world Hands-on Labs

We will develop almost 20 hands-on labs during the course. If we look at the some of the important hands-on labs of our course;

As you can see that we try to solve some real-world problems with AWS Lambda and Serverless architecture in our Hands-on labs.

Now let’s elaborate these problems and solutions of architecture designs and big picture of all these hands-on labs one by one.

Hands-on Lab: Single Calculator Microservice Expose https methods with Lambda Function Url

We will create a single Calculator Microservice and expose APIs with Function Url. In microservices architecture, each of the application components is decoupled and deployed and run independently. AWS Lambda-initiated functions is all you need to build a microservice.

Single Calculator Microservice Expose https methods with Lambda Function Url

A function URL is a dedicated HTTPS endpoint for AWS Lambda function.
So we can create and configure a function URL through the Lambda console or the Lambda API.

Hands-on Lab: Build Serverless Chat App with a WebSocket API and Lambda

We are going to develop Hands-on Lab: Build Serverless Chat App with a WebSocket API and Lambda. Basically we will create a serverless Chat app that we connect, sendMessage and disconnect with Websocket API.
We will handle incomming bidirectional request from Websocket API of API Gateway into Lambda function and return back to immediate repsonse.

Hands-on Lab: Build Serverless Chat App with a WebSocket API and Lambda

Hands-on Lab: Building RESTful Microservices with AWS Lambda, API Gateway and DynamoDB

When building a microservice, you’re thinking about how a business context can be delivered as a re-usable service for your consumers. We are going to create a serverless API that creates, reads, updates, and deletes items from a DynamoDB table.

Hands-on Lab: Building RESTful Microservices with AWS Lambda, API Gateway and DynamoDB

Clients send request our microservices by making HTTP API calls. Amazon API Gateway hosts RESTful HTTP requests and responses to customers.
In this scenario, API Gateway provides built-in authorization, throttling, security, fault tolerance, request/response mapping, and performance optimizations. AWS Lambda contains the business logic to process incoming API calls and leverage DynamoDB as a persistent storage.
Amazon DynamoDB persistently stores microservices data and scales based on demand. Since microservices are often designed to do one thing well, a schemaless NoSQL data store is regularly incorporated.

Hands-on Lab: Secure your API Gateway with Amazon Cognito User Pools

We are going to do Hands-on Labs: Secure our API Gateway with Amazon Cognito User Pools. So that means authentication via Amazon Cognito will be added to the setup.

Hands-on Lab: Secure your API Gateway with Amazon Cognito User Pools

1- A client sends a request to the REST API configured in the API Gateway;
2- The API Gateway sends the request to the lambda function;
3- The lambda function executes and sends its response to the API Gateway;
4- The API Gateway sends the response to the client.

Hands-on Lab: Using an Amazon S3 trigger to invoke a Lambda function and persist on DynamoDB

Several AWS services, such as Amazon S3 and Amazon SNS invoke functions asynchronously to process events. When you invoke a function asynchronously, you don’t wait for a response from the function code.

Hands-on Lab: Using an Amazon S3 trigger to invoke a Lambda function and persist on DynamoDB

This is used an Amazon S3 trigger to invoke a Lambda function and persist on DynamoDB.

1- Upload object into bucket
2- Invoke a function in response to resource lifecycle events
3- Save uploaded file metadata in DynamoDB

Hands-on Lab: Fan-Out Serverless Architectures Using SNS, SQS and Lambda

Basically we are following e-commerce architecture and use case is order processing. First of all, a customer using a web or mobile application and place an order. The client app sends this request to Amazon API Gateway endpoint. This endpoint is the “front door” of the application.

Hands-on Lab: Fan-Out Serverless Architectures Using SNS, SQS and Lambda

This Order Acknowledgment Microservice does 4 thing;
1- first it verifies the request and generates the order Id
2- insert item order data into dynamodb table
3- Lambda sends a confirmation message back to api gateway with order Id

And lastly, this microservices publish a message to Amazon SNS which will be send downstream to different microservices. This message will be pub/sub messaging using SNS and this Order Acknowledgment Microservice will be the publisher of message.

Hands-on Lab: Process DynamoDB using AWS Lambda for Change Data Capture of DynamoDB Tables

We will develop DynamoDB Streams — Using AWS Lambda to Process DynamoDB Streams for Change Data Capture of DynamoDB Tables. DynamoDB supports streaming of item-level change data capture records in the near-real time. We can build applications that consume these streams and take action based on the contents.

Hands-on Lab: Process DynamoDB using AWS Lambda for Change Data Capture of DynamoDB Tables

AWS maintains separate endpoints for DynamoDB and DynamoDB Streams. To read and process DynamoDB Streams records, your application must access a DynamoDB Streams endpoint in the same Region.

Hands-on Lab: Process Kinesis Streams using AWS Lambda for Change Data Capture of DynamoDB Tables

Amazon Kinesis makes it easy to collect, process, and analyze real-time, streaming data. Amazon Kinesis offers key capabilities to cost-effectively process streaming data at any scale.

Hands-on Lab: Process Kinesis Streams using AWS Lambda for Change Data Capture of DynamoDB Tables

Use case with Kinesis Data Streams

  • Accelerated log and data feed intake and processing
  • Real-time metrics and reporting
  • Real-time data analytics
  • Complex stream processing

Hands-on Lab: AWS Serverless Microservices for Ecommerce Application using Amazon EventBridge

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.

Hands-on Lab: AWS Serverless Microservices for Ecommerce Application using Amazon EventBridge

We have several microservices and integration components;

Product Microservices is basically implementing RESTful Microservices with using AWS Lambda, API Gateway and DynamoDB for performing CRUD operations.

Basket Microservices is implementing RESTful Microservices like Product microservices. But also Basket Microservices creates and trigger Checkout Basket event to the Amazon EventBridge for Event-Driven asynchronous Communication between Microservices in order to Decoupling Basket and Ordering Microservices.

After that Amazon EventBridge publish Checkout event to the AWS SQS and this SQS queue messages receive from Ordering microservices in order to processing events asynchronously using queues.

Hands-on Lab: Saga Pattern for Orchestrate Distributed Transactions using AWS Step Functions

Microservices are organized around business capabilities with a separate database per microservices. Microservices are loosely coupled and they use asynchronous messaging to communicate with each other.

Lets think microservices on e-commerce domain, Order Fulfillment Process Analysis:

Hands-on Lab: Saga Pattern for Orchestrate Distributed Transactions using AWS Step Functions

Customer place an order using frontend channels and API Gateway invoke Order microservices. And Order Fulfillment Process is started Order is going to check if the item is available in the Inventory microservice. If Inventory is available, deduct item in Inventory and it goes to Payment microservice. If Payment is successfully, It starts to Delivery microservice when deliver is done, order status will be completed.

If one of this steps are not successfully, it should rollback the steps and return back to previous status.

Step by Step Design AWS Architectures w/ Course

I have just published a new course — AWS Lambda & Serverless — Developer Guide with Hands-on Labs.

In this course, we will learn almost all the AWS Serverless Services with all aspects. We are going to build serverless applications with using AWS Lambda, Amazon API Gateway, Amazon DynamoDB, Amazon Cognito, Amazon S3, Amazon SNS, Amazon SQS, Amazon EventBridge, AWS Step Functions, DynamoDB and Kinesis Streams. This course will be 100% hands-on, and you will be developing a real-world application with hands-on labs together and step by step.

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.

--

--

Mehmet Ozkaya
AWS Lambda & Serverless — Developer Guide with Hands-on Labs

Software Architect | Udemy Instructor | AWS Community Builder | Cloud-Native and Serverless Event-driven Microservices https://github.com/mehmetozkaya