вторник, 22 октября 2013 г.

How to use Amazon Web Services Auto Scaling Groups

This post we will cover all the commands to create and managed Amazons Auto Scaling Groups

What is an Auto Scaling Group?

Auto Scaling allows you to scale your Amazon EC2 capacity up or down automatically according to conditions you define. With Auto Scaling, you can ensure that the number of Amazon EC2 instances you’re using increases seamlessly during demand spikes to maintain performance, and decreases automatically during demand lulls to minimize costs.
Now you will need an Amazon Machine Image (AMI)

What is an Amazon Machine Image (AMI)?

An Amazon Machine Image (AMI) is a special type of pre-configured operating system and virtual application software which is used to create a virtual machine within the Amazon Elastic Compute Cloud (EC2). It serves as the basic unit of deployment for services delivered using EC2.
Let’s imagine you have an AMI: ami-xxxxxx
Before you can create an Auto Scaling Group you need a Launch Configuration

What is a Launch Configuration?

A Launch Configuration defines the AMI to be used, the size of the EC2 instances to be used, the security group the instances will live in and the private key used to decrypt the password in Windows or for gaining access via SSH
How to create a Launch Configuration?
?
1
2
// create launch config
as-create-launch-config my-launch-config-1 --image-id ami-xxxxxx --region eu-west-1 --instance-type m1.small --group my-securitygroup-sg --key myKey
How to check the launch configuration has been created?
?
1
2
// check launch config has been created
as-describe-launch-configs --headers --region eu-west-1  --max-records 50
or check just your launch config has been create
?
1
2
// check your launch config has been created
as-describe-launch-configs my-launch-config-1 --headers --region eu-west-1  --max-records 50
How to delete a launch configuration?
?
1
2
// delete launch config
as-delete-launch-config my-launch-config-1 --region eu-west-1
How to creating an Auto Scaling Group?
?
1
2
// create auto scaling group
as-create-auto-scaling-group my-auto-scaling-group --region eu-west-1 --launch-configuration my-launch-config-1 --availability-zones eu-west-1a eu-west-1b eu-west-1c --min-size 3 --max-size 3 --desired-capacity 3 --default-cooldown 5 --grace-period 5 --tag "k=Name, v=my-server, p=true" --tag "k=enabled, v=true, p=true"
How to check the Auto Scaling Group has been created?
?
1
2
// check auto scaling group has been created
as-describe-auto-scaling-groups --headers --region eu-west-1
How to add or update the Auto Scaling Group tags?
Add or update the Name tag
?
1
2
// add or update the tag
as-create-or-update-tags --tag "id=my-auto-scaling-group, t=auto-scaling-group, k=Name, v=my-server, p=true" --region eu-west-1
Add or update a custom ROLE tag
?
1
2
// add or update the tag
as-create-or-update-tags --tag "id=my-auto-scaling-group, t=auto-scaling-group, k=ROLE, v=production, p=true" --region eu-west-1
Add or update a custom ALLOWED_IPS tag
?
1
2
// add or update tag
as-create-or-update-tags --tag "id=my-auto-scaling-group, t=auto-scaling-group, k=ALLOWED_IPS, v=XXX.XXX.XXX.XXX, p=true" --region eu-west-1
How to scale up the Auto Scaling Group?
This would scale your group of instances up to 6 and set a max of 12
?
1
2
// scale up
as-update-auto-scaling-group my-auto-scaling-group --region eu-west-1 --min-size 6 --max-size 12 --desired-capacity 6
How to scale down the Auto Scaling Group?
This would scale your group of instances up to 3 and set a max of 6
?
1
2
// scale down
as-update-auto-scaling-group my-auto-scaling-group --region eu-west-1 --min-size 3 --max-size 6 --desired-capacity 3
How to set zero instances in the Auto Scaling Group?
This would remove all instances, but keep the auto scaling group configuration ready for use in the future
?
1
2
// with zero instances
as-update-auto-scaling-group my-auto-scaling-group --desired-capacity 0 --max-size 0 --min-size 0 --region eu-west-1
How to delete an Auto Scaling Group?
?
1
2
// delete auto scaling group
as-delete-auto-scaling-group my-auto-scaling-group --region eu-west-1
How to get the Auto Scaling Groups latest activities?
This is handy for trouble shooting problems with your Auto Scaling Group
?
1
2
// to get latest actions
as-describe-scaling-activities --auto-scaling-group my-auto-scaling-group --region eu-west-1
How to update the Auto Scaling Group Configuration
This command lets you change auto scaling group configuration, zones, the min, max and desired number of instances
?
1
2
// with many options
as-update-auto-scaling-group my-auto-scaling-group --launch-configuration my-launch-config-2 --availability-zones eu-west-1a eu-west-1b eu-west-1c --desired-capacity 3 --max-size 3 --min-size 3 --region eu-west-1
How to change the Auto Scaling Group’s Launch Configuration
This will set a new launch configuration for the auto scaling group
?
1
2
// with new launch config
as-update-auto-scaling-group my-auto-scaling-group --launch-configuration my-launch-config-2 --region eu-west-1

Further Reading

Комментариев нет: