Deploying Web Applications on AWS ECS Spot Instances

1. What is AWS ECS?

  • Amazon ECS is a fully managed container orchestration service that makes deploying, managing, and scaling containerized applications easy.
  • It deeply integrates with the rest of the AWS platform to provide a secure and easy-to-use solution for running container workloads in the cloud and now on your infrastructure with Amazon ECS Anywhere.
  • Amazon ECS comes with AWS configuration and operational best practices built-in.
  • It also means you don’t need to manage control planes, nodes, or add-ons. It’s integrated with tools such as Amazon Elastic Container Registry and Docker. This integration makes it easier for teams to focus on building the applications, not the environment.

2. What is AWS Spot Instance?

  • A Spot Instance is an instance that uses spare EC2 capacity that is available for less than the On-Demand price.
  • Because Spot Instances enable you to request unused EC2 instances at steep discounts, you can significantly lower your Amazon EC2 costs.

3. What is our use case?

  • We will deploy the customer’s dockerized applications to AWS ECS-managed container service.
  • We are using Amazon Linux-based spot instances to deploy the application on an Autoscaling group to scale up and down the spot instances based on the traffic received to the application deployed on AWS ECS.
  • A Network load balancer will serve customer requests from outside, where the application and entire ECS environment will be deployed inside AWS private subnet.

Below is the architecture that explains our use case.

4. Configuring AWS ECS

  • A launch template is created, which contains the details for launching the necessary EC2 instances to serve the application running.
  • In the current setup, we have selected a custom AMI to launch instances and added the necessary AWS role to ensure the instances are added to the ECS cluster.
  • A plane AMI can also be selected based on the application type being deployed to the container.
  • Add the SSH keys and a role with necessary permissions for the instances to communicate with other AWS services like AWS Cloud watch for logging or AWS SNS service to notify teams with instance monitoring metrics.
  • The launch template user data should contain one important detail related to the ECS cluster.
  • The above User data in the launch template version helps the AWS Autoscaling group identify the exact AWS ECS cluster deploying the containers and add the EC2 spot instances to the corresponding cluster.
  • Have the Request Spot Instances box checked to No. We want to provision the spot instances from the Autoscaling group level.
  • User data configuration helps set up the ECS environment for deployable containers on ECS by the Spot instance passing all the health checks.
  • Above details containing the launch template are added to the Autoscaling group for scale-up and down purposes.

Creating an AWS Autoscaling Group:

  • While creating the AWS ASG. Instance type requirements need to be checked because these details will help provision the instances by ASG in case there is any shortage of specific instances in the spot restricted to the specific region where the cluster is set up.
  • Check the launch template version on the Autoscaling group is set to the Latest. This helps whenever there are more versions on a single launch template, as the Autoscaling group will pick the latest version to bring up the resources mentioned.
  • Once the instance requirements are set, we must look into Instance purchase options.
  • Here, the option to spot capacity needs to be justified at 100. So the ASG will have complete authority to spin up the spot instances instead of on-demand instances.
  • Finally, set the allocation strategy to capacity-optimized as recommended and check the capacity rebalance.
  • Create a Dynamic scaling policy for the ASG servers to scale in and out during heavy traffic on the load balancer.
  • These policies check the CPU for every minute, scale-up instances, and scale down one instance when the CPU is less than 50%. Once the ASG is created with the above parameter, AWS Spot instances will appear inside the cluster’s AWS ECS console.
  • A launch template and ECS service are required to deploy the containerized docker image on the spot instances of the ECS cluster.
  • Navigate to the Elastic Container Service in the menu and choose Task Definitions from the left-hand bar.
  • Create a new Task Definition.
  • Enter the values below for Task Definition Name and Network mode and click “Add Container”.
  • Add the container image details from ECR to the Task definition for the Service to pull the images onto spot instances.
  • Configure the new Service with the above Task definition by setting the task number to 2.
  • So inside the spot instance, 2 containers will be scaled up.
  • Select the load balancer details followed by the target group details to serve the requests to containers or tasks running inside the Service.
  • Set the Autoscaling of Service to configure.
  • Set up Automatic Task scaling policies to ensure the Tasks running on the Service will consider the policy a metric to scale in and out.
  • Given policy a name and Target value for the metrics.
  • Click on the next step, review the entire Service and click Create Service, which will pull the images from ECR and deploy them on the ECS console.

5. Summary

  • Amazon Elastic Container Service (Amazon ECS)is a highly scalable, high-performance container orchestration service that supports Docker containers and allows you to dash and scale containerized applications on AWS.
  • Amazon ECS eliminates the need to install and operate your own container orchestration software, manage and scale a cluster of virtual machines, or schedule containers on those machines.

Written by – Karanam sreenivas

Share

Search Post

Recent Posts

The role of cloud consulting in enhancing customer experience
July 22, 2024
Exploring Different Cloud Computing Models: Public, Private, and Hybrid
July 16, 2024
Top benefits of working with AWS consulting partners
July 15, 2024

Categories

Tags

Subscribe to the
latest insights

Subscribe to the latest insights

Related Posts

The role of cloud consulting in enhancing customer experience

Exploring Different Cloud Computing Models: Public, Private, and Hybrid

Top benefits of working with AWS consulting partners

Get in Touch!

Are you prepared to excel in the digital transformation of healthcare with Rapyder? Let’s connect and embark on this journey together.

I accept T&C and Privacy