Create Auto Scaling Resources

Create the Auto Scaling Resources

Create an Auto Scaling launch configuration

  1. Open the Amazon EC2 console.

  2. On the navigation bar at the top of the screen, select default region.

  3. On the navigation pane, under Auto Scaling, choose Launch Configurations.

  4. On the next page, choose Create launch configuration.

  5. For Launch configuration name, enter ASGLaunchConfig-TripmgmtDemo for the launch configuration name.

  6. Get the Amazon ECS-optimized Amazon Linux 2 AMI id for your respective default region from AWS CLI. Look for image_id value from output of below command.

    aws ssm get-parameters --names /aws/service/ecs/optimized-ami/amazon-linux-2/recommended --region $AWS_DEFAULT_REGION
    
  7. On the Amazon machine image (AMI) section, search and choose given AMI ID.

    ECS Optimized Image

  8. On the Instance Type section, search and select t3.2xlarge. Here, t3.2xlarge selected as an example, you can choose EC2 Instance size as per your need.

  9. On the Additional configuration Section, do the following:

    1. For IAM instance profile, select already created container instance IAM role ecsInstanceRole

    2. Expand the Advanced Details section to specify user data for your Amazon ECS container instances.

      The Linux variants of the Amazon ECS-optimized AMI look for agent configuration data in the /etc/ecs/ecs.config file when the container agent starts. You can specify this configuration data at launch with Amazon EC2 user data.

      Paste the following script into the User data field - as Text. The ecs-cluster-tripmgmtdemo cluster was created in above step. It configures launched EC2 instance for given ECS Cluster.

      #!/bin/bash
      echo ECS_CLUSTER=ecs-cluster-tripmgmtdemo >> /etc/ecs/ecs.config
      
  10. On the Security groups Section, do the following:

    • Choose Create new security group, and Allow All TCP inbound traffic from Application Loadbalancer Security Group you have created in earlier section (i.e. sg-xxxxx).
  11. On the Key pair (login) Section, select Proceed without a key pair.

  12. Choose Create launch configuration.

  13. Go to Launch Configurations and click on newly created Launch Configuration. From the Details tab, make a note of the newly created Security Group Id (i.e. sg-xxxxxxxx..)

Next, create an Auto Scaling group using that launch configuration.

To create an Auto Scaling group

  1. Open the Amazon EC2 console.

  2. On the navigation bar at the top of the screen, select default region.

  3. On the navigation pane, under Auto Scaling, choose Launch Configurations.

  4. On the next page, select the launch configuration we created in above step and choose Create Auto Scaling group from Actions.

    ASG Create

  5. On the Configure Auto Scaling group details pages, do the following:

    1. For Group name, enter ASG-TripmgmtDemo for the Auto Scaling group name.
    2. For Network, choose a VPC for your Auto Scaling group and for Subnet, choose same subnets in your VPC which was selected for Application Load Balancer section.
    3. For Group size, enter 0 for Desired and Minimum capacity and 10 for Maximum capacity. We will use Amazon ECS managed scaling so there is no need to have the Auto Scaling group launch any initial instances.
    4. For Scaling policies section, select None. We will use Amazon ECS managed scaling so there is no need to create a scaling policy.
    5. For Instance scale-in protection, check mark Enable instance scale-in protection. This enables you to use managed termination protection for the instances in the Auto Scaling group, which prevents your container instances that contain tasks from being terminated during scale-in actions.
  6. Choose Review, Create Auto Scaling group.

  7. Repeat steps 3 to 6 to create a second Auto Scaling group but for Group name use ASG-TripmgmtDemo-burst.