Run MicroServices on AWS Serverless Platform (AWS Fargate)

Introduction

Hari Manikkothu
Kubernetes
4 min readMay 29, 2020

--

The serverless architecture enables you to shift more of the operational responsibilities to the cloud service provider. The user does not need to worry about the infrastructure management and thus can focus more on building and managing their application life cycle. The fault tolerance and availability aspect also will be taken cared by the cloud service provider.

AWS Fargate is the serverless platform from AWS. It eliminate the need to manage the cluster or EC2 instances, rather lets the user focus on managing the application lifecycle.

Deployment Architecture

As per the Well-Architechted guide lines, we’ll use three private subnets, each on separate AZs to deploy the containers. Three public subnets will be used to provision the ALB, and NATs if needed. Provision the endpoints to access the managed service APIs internally as shown above.

Dev environment and Tools setup

We’ll use the cloud9 IDE for this demo. Setup the cloud9 IDE using the instructions here.

Install ecs-cli, other utilities

Configure defaults

Clone Repos

Clone the following repos to get the sample code and templates used in the demo

Build VPC, ECS Cluster, ALB

AWS CloudFormation provides a way to use simple text/yaml file to model and provision resources in an automated and repeatable way. In this example we’ll use cloud formation templates for creating the VPC/Subnets, Cluster and ALBs

Build VPC, Cluster

The cloud formation template cluster-fargate-vpc.yml defines the VPC, Subnets, IG, NATs, Security Groups, Route Tables and the Cluster.

Build ALB

The cloud formation template ‘alb-external.yml’ create an ALB, associate it with all three public subnets, and creates a dummy target group which will be used to load balance the ECS tasks later.

Deploy Backend Service Container

Set env variables

Configure default lauch_type and cluster for ecs-cli

This creates an entry in ‘/home/ec2-user/.ecs/config’ file with the given params.

Deploy backend service

ecs-cli looks for two files in the current folder to load task definitions and run params — ‘ecs-params.yml’ and ‘docker-compose.yml’. Lets take a look at the content of both.

docker-compose.yml — configures the image and logging info.

ecs-params.yml (templated from ecs-params.yml.template) — Contains task definition, network configuration and service discovery configurations.

Run the following commands to deploy

envsubst templates the ecs-params.yml with the current values.

The above command also creates private dns namespace for service discovery, and log group in cloudwatch logs. The service can be accessed by other microservices using ‘http://ecs-nodejs-backend.service:<port>’ end point. This will be used in our frontend container as an env variable.

Deploy Frontend Service Container

Note that the command uses ‘target-group-arn’ param, which will ensure the containers are associated with the ALB target group.

Also, note that the container definition in ‘docker-compose.yml’ sets the backend url as an environment variable.

Test

Get the ALB external usr as follows

Open the url in browser, validate the response from frontend service.

References

--

--

Hari Manikkothu
Kubernetes

kubernetes enthusiast | AWS certified Solution Architect