- We'll be using the AWS CLI in this recipe, a command-line utility written in Python, that makes interacting with the AWS API easy. We'll assume you have an AWS account and have installed and configured the AWS CLI application. Consult the AWS documentation (https://docs.aws.amazon.com/cli/latest/index.html#) for installation instructions.
- Create a launch configuration. Launch configurations are templates that our Auto Scaling Groups will use for creating new EC2 instances. They contain information such as the instance type and size that we want to use when creating new instances. Give your launch configuration a unique name–in our case, we'll simply call it users-service-launch-configuration:
$ aws create-launch-configuration --launch-configuration-name users-service-launch-configuration \
--image-id ami-05355a6c --security-groups sg-8422d1eb \
--instance-type m3.medium
- Create an Auto Scaling Groups that uses our new launch configuration:
$ aws create-auto-scaling-group --auto-scaling-group-name users-service-asg \
--launch-configuration-name users-service-launch-configuration \
--min-size 2 \
--max-size 10
- Create an ELB, as follows:
$ aws create-load-balancer --load-balancer-name users-service-elb \
--listeners "Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=8080"
- Attach the ASG to our load balancer by running the following command line:
$ aws autoscaling attach-load-balancers --auto-scaling-group-name users-service-asg --load-balancer-names users-service-elb