Hands-on Microservices With Docker on AWS (Part 4)

Part 1, Part 2, Part 3, Part 4


This is the final article in this series. This time we will incrementally build and deploy each microservice using Fargate. This time we really break apart the application into many small pieces of services.

Solution Diagram

We will use Fargate to deploy these microservices. However, this time we will walk through all the deployment steps for a fresh service.

Build and Deploy Microservice

Go back to Cloud9 and uncomment this block.

Then type below command to add new function to the application and rebuild the docker image.

cd amazon-ecs-mythicalmysfits-workshop/workshop-1/app/monolith-service
docker build -t monolith-service:nolike .
docker tag monolith-service:nolike ECR_REPOSITORY_URI:nolike  docker push ECR_REPOSITORY_URI:nolike

The ECR_REPOSITORY_URI is located on ECS=>Repositories if you forget.

After pushing, we can see a new image in ECR repositories.

Similarly, this now we copy the like-service ECR repository URI.

Back to Cloud9 and paste below command to build and push like-service.

cd ~/environment/amazon-ecs-mythicalmysfits-workshop/workshop-1/app/like-service
docker build -t like-service .
docker tag like-service:latest ECR_REPOSITORY_URI:latest
docker push ECR_REPOSITORY_URI:latest

Then now we can also see the like-service latest image is pushed into ECR repository.

Go to task definitions and create new task definitions.

Click Next.

Give it a name as mysfits-like and select mysfits-fargate-EcsService as Task execution role. Also choose the smallest memory and CPU which are good enough.

Click Add container under Container Definitions.

Give a name to the container, say mysfits-like. Paste the image URI we copied previously, set port 80.

Type the Key and value under Environment. Key should be MONOLITH_URL while value is ALB DNS name.

In case you forget how to find the DNS name, one way is to find it on Cloud9 cfn-output.json. Then click Add.

Scroll down and create.

When we see the success message, click View task definition.

Click Actions=>Create Service.

Select FARGATE, give a service name, say mysfits-like-service, and set 1 task.

Scroll down and click Next.

Select the same VPC as before, but this time we choose private subnet.

Scroll down and choose ALB.

Click Add to Load Balancer.

Please follow my setting. Listener port is 80, the new target group name is mysfits-like, Path pattern is /mysfits/*/like, Evaluation order is 1 and Health check path is /. Finally, click Next and Next.

Now we create service.

Choose View Service.

Wait for the creation until the status is running.

Go to S3 bucket=>properties and open this URL.

Now we are able to click “Adopt Me Now!”.

Once we clicked, we can see “Like processed” in logging.


For ECS service, we select it and click update.

Both desired tasks are set to 0.

Delete the repositories.

In EC2=>Load Balancer, select the ALB and click Actions=>Delete.

Also delete all the log groups in CloudWatch.

Finally, delete the stack in CloudFormation.

Leave a Reply