Software Development optimize

Installing and checking Amazon Auto Scaling and CloudWatch tools

Nick Hardiman details the steps and commands involved in installing and checking Amazon's Auto Scaling and CloudWatch tools.

There are many steps to follow to set up auto-scaling. This time I add two more sets of Amazon tools to my local machine and add my first bit of auto-scaling configuration.

I need Amazon's EC2, Auto Scaling and CloudWatch tools to make rules for the CloudWatch and Auto Scaling processes to follow. I need no less than 22 commands to do my work, and each one is a bit of monster like this one.

mon-get-stats CPUUtilization \
--statistics "Average" \
--namespace "AWS/EC2" \
--dimensions "AutoScalingGroupName=cag01"

You may think this kind of complexity is exactly the kind of thing that makes the command line unpopular. I could not possibly comment.

Amazon Auto Scaling behind the scenes

The things that make auto-scaling work are hidden from the customer: secret processes run behind the scenes at every AWS site, managing the action. CloudWatch processes continuously monitor my service, and kick off Auto Scaling when required. The tasks of the CloudWatch processes are to:

  • Monitor the service.
  • Raise the alarm when something goes wrong.
  • Start Auto Scaling.

The job of the Auto Scaling processes is to:

  • Make one change.

And that's it. Auto Scaling stops after that. Nothing else happens until CloudWatch hands over to Auto Scaling again.

Amazon Auto Scaling Command Line Tools

The Auto Scaling Command Line Tools are a collection of programs supplied by Amazon for free. Customers can run these tools on their local machines to set up automatic scale-out of their remote services. They are written in Java and require a Java virtual machine to obey their commands.

Setting up these auto-scaling tools is similar to setting up the EC2 API Tools -- download, install, tweak the environment, and check that it works by running a simple command that won't break anything. This procedure adds 39 commands to your toolkit. All these commands start with the letters as-, similar to the way all the EC2 tools started with ec2-.

File download security is slightly worrying. For some reason, Amazon has not bothered providing any security checks: there is no way of verifying the download file. The EC2 Tools install procedure included a way to "Verify the signature of command line tools," but the Auto Scale Tools install does not. No, I have no idea why.

Install the Auto Scaling tools

The install procedure is simple.

  1. Download the Auto Scaling Tools archive..
  2. Unpack into a directory.
  3. Change the PATH environment variable, to make sure my shell can find these tools. export AWS_AUTO_SCALING_HOME=/Users/nick/Documents/AWS/AutoScaling-1.0.49.1export PATH=$PATH:$AWS_AUTO_SCALING_HOME/bin
  4. Check that it works.

Check your work

An easy way to check is to run a command -- any AWS command -- with the help option. This displays a manual page describing how to use the command.

My-MacBook-Pro:~ nick$ as-cmd --help
Command Name                                Description
------------                                -----------
as-create-auto-scaling-group                Create a new Auto Scaling group.
...
version                                     Prints the version of the CLI tool and the API.
    For help on a specific command, type '<commandname> --help'
My-MacBook-Pro:~ nick$

Troubleshoot

If you haven't set up your environment variables, this won't work.

Amazon CloudWatch Tools

The Amazon CloudWatch Command Line Tools are another collection of commands (not many -- 13 in total) starting with the prefix mon-.

Install the CloudWatch Tools

The install procedure is practically the same as installing the Auto Scaling  Command Line Tools.

  1. Download the CloudWatch Tools archive.
  2. Unpack into a directory.
  3. Make sure my shell can find these tools export AWS_CLOUDWATCH_HOME=/Users/nick/Documents/AWS/CloudWatch-1.0.12.1export PATH=$PATH:$AWS_CLOUDWATCH_HOME/bin
  4. Check that it works.

My-MacBook-Pro:~ nick$ mon-cmd --help
Command Name                       Description
------------                       -----------
help
mon-delete-alarms                  Delete alarms
...
For help on a specific command, type '<commandname> --help'
My-MacBook-Pro:~ nick$

Add a launch configuration using the Auto Scaling Tools

The action starts with the commands:

  • ec2-describe-images
  • as-create-launch-config
  • as-describe-launch-configs

The first command, as-create-launch-config, creates the first rule and names it clc01 (Customer-facing Launch Configuration no.1). This defines what gets scaled out.

First, I have to make sure my new AMI is available.

My-MacBook-Pro:~ nick$ ec2-describe-images
IMAGE  ami-1234c141 123494605340/IM CMS image  123494605340 available    private             x86_64 machine      aki-1234c435               ebs    paravirtual  xen
BLOCKDEVICEMAPPING  /dev/sda            snap-12346b27 8
My-MacBook-Pro:~ nick$

Looking good.

Add the launch rule.

My-MacBook-Pro:~ nick$ as-create-launch-config clc01 \
> --group         sg-1234a9ab \
> --image-id      ami-1234c141 \
> --instance-type   m1.small
OK-Created launch config
My-MacBook-Pro:~ nick$

What do those options mean?

  • group sg-1234a9ab - My security group. This is similar to the default quick-start-1 group, with some extra customer service ports open.
  • image-id ami-1234c141 - I am not using the default Amazon image here, like I did during my first experiments. This is my own AMI, based on one of Rightscale's images.
  • instance-type m1.small - Machine size. A small machine from Amazon is not suitable for providing web services to customers, but it is good for scaling experiments.

Check your work.

Can I see my new config?

My-MacBook-Pro:~ nick$ as-describe-launch-configs
LAUNCH-CONFIG  clc01  ami-1234c141  m1.small
My-MacBook-Pro:~ nick$

Troubleshoot

If I forget to set the EC2_URL environment variable, I get a service error like this.

My-MacBook-Pro:~ nick$ as-create-launch-config clc01 \
> --group         sg-1234a9ab \
> --image-id      ami-1234c141 \
> --instance-type   m1.small
as-create-launch-config:  Service error: AMI ami-1234c141 is invalid: The AMI ID 'ami-1234c141' does not exist  AWSRequestId:fc1e7c64-b3ee-11e1-9da6-b96664ed80a7
My-MacBook-Pro:~ nick$

Next time, I will add an Auto Scaling Group.

About

Nick Hardiman builds and maintains the infrastructure required to run Internet services. Nick deals with the lower layers of the Internet - the machines, networks, operating systems, and applications. Nick's job stops there, and he hands over to the ...

0 comments