Amazon Web Services (AWS) launched a beta of their new concept Elastic Beanstalk in January. AWS Elastic Beanstalk allows you to in a few clicks setup a new environment where you can deploy your application. Say you have a development team developing a web-app running on Tomcat and you need a test server where you can test your application. In a few simple steps you can setup a new machine with a fresh installation of Tomcat where you can deploy your application. You can even use the AWS Elastic Beanstalk command line client to deploy your application as simple as with:
$ elastic-beanstalk-update-application -a my_app.war -d "Application description"
I had the opportunity to try it out and I would like to share how you get started with the service.
As with other AWS cloud based services, you only pay for the resources your application consumes and if you’re only interested in a short evaluation, it will propably only cost you a couple of US dollars. This first release of Elastic Beanstalk is targeted for Java developers who are familiar with the Apache Tomcat software stack. The concept is simple, you simply upload your application (e.g. war-packaged web application) to a Elastic Beanstalk instance through the AWS web interface called the Management Console. The Management Console allows you to handle versioning of your applications, monitoring and log viewing straight throught the web interface. It also provides load balancing and scaling out of the box. The Elastic Beanstalk service is currently running on a 32-bit Amazon Linux AMI using Apache Tomcat 6.0.29.
But what if you would like to customize the software stack your application is running on? Common tasks you might want to do is adding jar-files to the Tomcat lib-directory, configure connection pooling capabilities, edit the Tomcat server.xml or even install third party products such as ActiveMQ. Fortunatly, all of this is possible! You first have to create your custom AMI (Amazon Machine Image). Go to the EC2 tab in the Management Console, select your default Elastic Beanstalk instance and select Instance Actions > Create Image (EBS AMI). You should then see your custom image under Images / AMIs in the left menu with a custom AMI ID. Back in the Elastic Beanstalk tab, select Environment Details of the environment you want to customize and select Edit Configuration. Under the Server tab, you can specify a Custom AMI ID to your instance, which should refer to the AMI ID of your newly created custom image. After applying the changes, your environment will “reboot”, running your custom AMI.
Now you might ask yourself, what IP address do my instance actually have? Well, you have to assign an IP address to it first. You can then either use this IP or the DNS name to log in to your instance. AWS is using a concept called Elastic IPs, which means that they provide a pool of IP addresses from where you can get a random free IP address to bind to your current instance. If you want to release the IP address from your instance, it is just as easy. All of this is done straight out of the Management Console in the EC2 tab under Elastic IPs. You just select Allocate Address and then bind this Elastic IP to your instance. To prevent users to have unused IP addresses lying around, AWS is charging your account for every unbound Elastic IP, which might end up a costful experience. So make sure you release your Elastic IP address back to the pool if you’re not using it.
To be able to log in to your machine, you will have to gerenate a key pair which is used as an authentication token. You generate a key pair in the EC2 tab under Networking & Security / Key Pairs. Then go back to the Elastic Beanstalk tab, select Environment Details of your environment and attach your key pair by providing it in the Server > Existing Key Pair field. You then need to download the key file (with a .pem extension by default) to the machine you will actually connect from. You also need to open the firewall for your instance to allow connections from the IP address you are connecting from. Do that by creating a security group Networking & Security Groups on the EC2 tab. Make sure to allow SSH over tcp for port 22 for the IP address you are connecting from. Then attach the security group to your Elastic Beanstalk environment by going to the Elastic Beanstalk tab and selecting Environment Details > Edit Configuration for your environment. Add the security group in the field EC2 Security Group on the Server tab.
So now you’re currently running a custom image (which is actually a replica of the default one) which has an IP address, a security group and a key pair assigned to it. Now is the time to log in to the machine and do some actual customization! Log in to your machine using ssh and the key you downloaded from your AWS Management Console, e.g.:
$ ssh -i /home/tommy/mykey.pem ec2-user@ec2-MY_ELASTIC_IP.compute-1.amazonaws.com
… where MY_ELASTIC_IP is the IP address of your machine, such as:
$ ssh -i /home/tommy/mykey.pem email@example.com
Please note the hyphens instead of dots in the IP address! Then, you’re good to go and start customizing your current machine! If you would like to save these configurations onto a new image (AMI), just copy the current AMI through the Management Console. You can then use this image when booting up new environments. You find Tomcat under /usr/share/tomcat6/. See below for a login example:
tommy@linux /host $ ssh -i /home/tommy/mykey.pem firstname.lastname@example.org The authenticity of host 'ec2-184-73-226-161.compute-1.amazonaws.com (22.214.171.124)' can't be established. RSA key fingerprint is 13:7d:aa:31:5c:3b:17:ed:74:6d:87:07:23:ee:33:20. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'ec2-184-73-226-161.compute-1.amazonaws.com,126.96.36.199' (RSA) to the list of known hosts. Last login: Thu Feb 3 23:48:38 2011 from 72-21-198-68.amazon.com __| __|_ ) Amazon Linux AMI _| ( / Beta ___|\___|___| See /usr/share/doc/amzn-ami/image-release-notes for latest release notes. [ec2-user@ip-10-122-194-97 ~]$ sudo su - [root@ip-10-122-194-97 /]# ls -al /usr/share/tomcat6/ total 12 drwxrwxr-x 3 root tomcat 4096 Feb 3 23:50 . drwxr-xr-x 64 root root 4096 Feb 3 23:50 .. drwxr-xr-x 2 root root 4096 Feb 3 23:50 bin lrwxrwxrwx 1 root tomcat 12 Feb 3 23:50 conf -> /etc/tomcat6 lrwxrwxrwx 1 root tomcat 23 Feb 3 23:50 lib -> /usr/share/java/tomcat6 lrwxrwxrwx 1 root tomcat 16 Feb 3 23:50 logs -> /var/log/tomcat6 lrwxrwxrwx 1 root tomcat 23 Feb 3 23:50 temp -> /var/cache/tomcat6/temp lrwxrwxrwx 1 root tomcat 24 Feb 3 23:50 webapps -> /var/lib/tomcat6/webapps lrwxrwxrwx 1 root tomcat 23 Feb 3 23:50 work -> /var/cache/tomcat6/workTommy Tynjä @tommysdk