Mostrando entradas con la etiqueta script. Mostrar todas las entradas
Mostrando entradas con la etiqueta script. Mostrar todas las entradas

domingo, 29 de junio de 2014

AWS: How to auto attach public IP from ElasticIP pool

When an EC2 instance is launched, you can select to attach a Public IP (or not). This Public IP is randomly selected. Here is an example:


i-cf27aa8d instance has 54.72.151.117 Public IP address assigned. This IP is taken from general AWS pool. If you stop and start the instance from AWS EC2 console, a different Public IP address will be selected.

Now, imagine instance launch is controlled by an auto-scaling policy. Following explained behavior, a new random Public IP address will be attached each time a new (or replacement) instance is launched attending auto-scaling group needs.

In the context of need a predictable Public IP addresses, general behavior doesn't fit our needs. When instance is launched manually is easy to resolve: you can attach an IP address from Elastic IP pool through AWS EC2 console, for example. But this could be difficult in an auto-scaling context.

A way to resolve this situation could be using ipassign script. Let verify this with an example!

Imagine previous instance (i-cf27aa8d). To use ipassign script we need to:

  • Verify AWS CLI and ec2-utils packages are installed. By default, Amazon Linux instances arrive with them pre-installed. For Ubuntu distributions, probably you'll need to install them manually using apt-get commands:

  • Login to the instance as root username. If role instance is not assigned, you need to configure AWS CLI with an IAM user allowed to execute describe-addresses, associate-address and disassociate-address EC2 actions.

  • Install ipassign script. Just follow next instructions:
  1. Download ipassign script and copy inside your instance in "/etc/init.d" directory
  2. Modify script permissions: chmod 755 /etc/init.d/ipassign
  3. Add script to instance startup process: chkconfig ipassign on
  • Review ipassign configuration. At the beginning of the script, there are two parameters you need to review and ensure are correctly configured:
  1. REGION: Defines the AWS region. Value must be the same used by instance. By default is set to eu-west-1 (Ireland) region.
  2. IPLOGFILE: Defines log file. By default is set to "/var/log/ipassign.log" and my suggestion is maintain this value.

Done! If we restart the instance, during startup process will try to attach a free Public IP address from Elastic IP pool. Imagine we have three IP address associated to our account, all of them are currently in use:


In this context, instance can't attach any Public IP. Script is designed to avoid changes if an IP from Elastic IP pool can't be attached. Next time we login to the instance, if we review log file will see an error message registered:


Just go to AWS EC2 web console and request a new Elastic IP:


Now (with a free Public IP in Elastic IP pool), if we restart instance again, we'll see ipassign script can find one free IP address in Elastic IP pool and attach it to the instance:


Login to the instance (now, using the new Public IP attached) and checking log file, next information is displayed:


Finally, in instance general information panel, we can review how the instance has a new Public IP address (54.76.166.221) from the Elastic IP pool correctly assigned:


By default, 5 Elastic IP addresses can be associated to an AWS account. But this limit could be increased, if needed.


lunes, 28 de abril de 2014

Test your ELB

ELB (Elastic Load Balancer) is a service provided by AWS to allow you include easily scalable load balancers in your architecture. But sometimes, you detect issues difficult to determinate if they are related with backend instances or ELB itself. Some alternatives in this situation: you can review your CloudWatch metrics trying to find any related issue or you can design a specific test to ensure your environment is working as expected.

In the second situation, several tools can be used to perform an in-depth test (jmeter, for example). But if you want to make an easy test based in a URL, testELB.sh could be what you need.

tesELB.sh will test an URL during a period (by default, ten minutes), making random queries through all associated IPs in your ELB. Additionally, will show you interesting information about:

  • Average response time
  • Maximum response time
  • Percentile 95 response time
  • Average payload size
  • Error request (including percent)
Here is an execution example:

testELB.sh output

Usage:

testELB.sh ELB [LOOP] [URL] [PORT] [PROTOCOL]

  ELB: DNS Name associated to ELB
  LOOP: Number of loops. Default value: 600 (ten minutes)
  URL: URL to check in ELB. Default value: /
  PORT: Port in ELB to check. Default value: 80
  PROTOCOL: Protocol to use. Default value: http

This shell script could be a good starting point to troubleshoot ELB issues. Fell free to use it!