November 06, 2018
This lab introduces an architectural evolvement of a simple web service application, from monolith to microservice. Both architectures are containerized with Docker. The lab also shows the advantages gained in system scalability by using microservice, which could be easily achieved via changing some configurations in AWS console, and even without having to shut down the application.
git clone https://github.com/awslabs/amazon-ecs-nodejs-microservices.git
name: api
Grant full access of container registry to group, then add user in group.
Get AWS Access Key ID and AWS Secret Access Key from last step, then
aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json
aws ecr get-login --no-include-email --region [region]
See Docker login information output, copy and paste to terminal to login ECS repository
docker login -u AWS -p ...
cd ~/amazon-ecs-nodejs-microservices/2-containerized/services/api
docker build -t api .
docker tag api:latest [account-id].dkr.ecr.[region].amazonaws.com/api:v1
docker push [account-id].dkr.ecr.[region].amazonaws.com/api:v1
Check in console, monolith is containerized.
aws cloudformation deploy \
--template-file ~/amazon-ecs-nodejs-microservice/2-containerized/infrastructure/ecs.yml \
--region <region> \
--stack-name BreakTheMonolith-Demo \
--capabilities CAPABILITY_NAMED_IAM
In 5 minutes, see stack ready in CloudFormation console,
The task definition tells Amazon ECS how to deploy your application containers across the cluster.
The Application Load Balancer (ALB) lets your service accept incoming traffic. The ALB automatically routes traffic to container instances running on your cluster using them as a target group.
Create and Configure the ALB Target Group
The listener checks for incoming connection requests to your ALB, and routes them to service groups.
Add a Listener to the ALB
Create Service on BreakTheMonolith-Demo-ECSCluster
Add Service to Target Group
You should see a message ‘Ready to receive requests’.
See Each Part of the Service
In this module, you will break the node.js application into several interconnected services and push each service’s image to an Amazon ECR repository.
ALB routes requests to 3 different target groups which are associated with microservice, whose instances are represented in Docker containers.
Service api is broken into 3 microservices,
Create Image Repository for Each Microservice
cd ~/amazon-ecs-nodejs-microservices/3-microservices/services
docker build -t [service-name] ./[service-name]
docker tag posts:latest [account-id].dkr.ecr.us-west-2.amazonaws.com/posts:v1
docker push [account-id].dkr.ecr.[region].amazonaws.com/[service-name]:v1
In this module, you will deploy your node.js application as a set of interconnected services behind an Application Load Balancer (ALB). Then, you will use the ALB to seamlessly shift traffic from the monolith to the microservices.
Create as in task api for,
Deploy on cluster as api for,
See tasks running,
Same way as in testing monolith deployment
Visit DNS name of load balancer
You should see a message ‘Ready to receive requests’.
See Each Part of the Service
AWS Tutorial: Break a Monolith Application into Microservices
Written by Warren who studies distributed systems at George Washington University. You might wanna follow him on Github