AWS Elastic Beanstalk

Cloud Giant

Give It a Poke

You can poke around a bit and have some fun by uploading a script like:

<?php
print_r($_SERVER);
?>

(Adjust this to whatever language you're using – just throw out the environment variables to see what is happening on that server.) To see the environment, use $_SERVER['/var/www/html/index.php'].

Git and Branches

One server is cool, but what about an application server for each branch, so you can push to one for development and to another for stable? Start by checking out a new branch,

$ git checkout -b stable

Then, ask eb what's going on (Listing 3).

Listing 3

Checking a New Branch

$ eb status
The current branch "stable" is not associated with an Elastic Beanstalk environment. Call "eb branch" to set up a new environment for this branch.
Proceeding with default settings.
URL : DanApp-env-ceqwdhduep.elasticbeanstalk.com
Status : Ready
Health : Green

The output suggests you call eb branch; to do so, enter:

$ eb branch
The current branch is "stable".
Enter an AWS Elastic Beanstalk environment name (auto-generated value is "DanApp-stable-env"):
Do you want to copy the settings from environment "DanApp-env" for the new branch? [y/n]: y

So, where are you now? To find out, enter:

$ eb status
Environment "DanApp-stable-env" is not running.

You know what to do about that: Start it up:

$ eb start
...the usual stuff

Now pause to realize that you've just changed branch, copied the *entire stack config*, and launched a clone of the live environment in a few lines. That is neat and means that when you try something, much as with a new way of caching on the homepage or logging in with Twitter, you can spend an extra couple of minutes sending it to your team to see what they think. When they say – "but will it work on the live servers?" – you can say, "yes," because you know it will.

While you're waiting, you can see two environments in the AWS web console. The startup is the same set of steps, but it's interesting to see that this is the stable version (Listing 4).

Listing 4

Startup in Web Console

Starting application "DanApp".
 Waiting for environment "DanApp-stable-env" to launch.
 2013-05-08 20:20:43 INFO createEnvironment is starting.
 2013-05-08 20:20:48 INFO Using elasticbeanstalk-eu-west-1-894012917938 as Amazon S3 storage bucket for environment data.
 2013-05-08 20:21:04 INFO Created load balancer named: awseb-e-h-AWSEBLoa-1118ULBZLSFGH
 2013-05-08 20:21:34 INFO Created security group named: awseb-e-hxaxpp3bsa-stack-AWSEBSecurityGroup-ZNUGTMANJ7WO
 2013-05-08 20:21:40 INFO Created Auto Scaling launch configuration named: awseb-e-hxaxpp3bsa-stack-AWSEBAutoScalingLaunchConfiguration-12RI7463WQWE3
 2013-05-08 20:23:25 INFO Waiting for EC2 instances to launch. This may take a few minutes.
 2013-05-08 20:23:25 INFO Created Auto Scaling group named: awseb-e-hxaxpp3bsa-stack-AWSEBAutoScalingGroup-1NMEE2RF9GMBP
 2013-05-08 20:25:11 INFO Created Auto Scaling group policy named: arn:aws:autoscaling:eu-west-1:894012917938:scalingPolicy:8bc35c42-856d-4848-8111-9ec4e4df0fcf:autoScalingGroupName/awseb-e-hxaxpp3bsa-stack-AWSEBAutoScalingGroup-1NMEE2RF9GMBP:policyName/awseb-e-hxaxpp3bsa-stack-AWSEBAutoScalingScaleDownPolicy-179VH5P3Y0VH9
 2013-05-08 20:25:13 INFO Created CloudWatch alarm named: awseb-e-hxaxpp3bsa-stack-AWSEBCloudwatchAlarmLow-1Q23UL8HF2B6K
 2013-05-08 20:25:16 INFO Created Auto Scaling group policy named: arn:aws:autoscaling:eu-west-1:894012917938:scalingPolicy:732bdc0c-4734-4d27-b02e-99d716c66dc6:autoScalingGroupName/awseb-e-hxaxpp3bsa-stack-AWSEBAutoScalingGroup-1NMEE2RF9GMBP:policyName/awseb-e-hxaxpp3bsa-stack-AWSEBAutoScalingScaleUpPolicy-1Q75QYV2QAY6X
 2013-05-08 20:25:18 INFO Created CloudWatch alarm named: awseb-e-hxaxpp3bsa-stack-AWSEBCloudwatchAlarmHigh-1AD9DJ2JI6IPZ
 2013-05-08 20:26:56 INFO Application available at DanApp-stable-env-3jhebnynie.elasticbeanstalk.com.
 2013-05-08 20:26:56 INFO Successfully launched environment: DanApp-stable-env
 Application is available at "DanApp-stable-env-3jhebnynie.elasticbeanstalk.com".

To get your app to appear at DanApp-stable-env-3jhebnynie.elasticbeanstalk.com , you need to push to it with git aws.push (Listing 5) and wait a couple of minutes. You now have two environments running, each running its own code, and each running its own virtualized hardware – and you haven't configured a single thing.

Listing 5

git aws.push

$ git aws.push
Pushing to environment: DanApp-stable-env
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 589 bytes, done.
Total 7 (delta 0), reused 0 (delta 0)
remote:
 To https://AKIAJ2XDUJ2NAFFPK5SA:20130508T193045Z74f087d7af6327f3447173d8dba5de13b9c695da67033b955885c5cb4a7226b1@git.elasticbeanstalk.eu-west-1.amazonaws.com/v1/repos/44616e417070/commitid/37346533646166656662386330633434363938363361616635383863363963356164326535346466/environment/44616e4170702d737461626c652d656e76 + 04156e4...74e3daf HEAD -> master (forced update)

Clean Up, Kill It All, and Rest

To finish, ruthlessly go through, using eb delete until everything is dead; then, sit back and enjoy how little work it took to launch so much stuff.

It's kind of mad that AWS throws out stuff that feels too bare, when they could ship things like this that are wrapped up a little more. Elastic Beanstalk has been the easiest and most sensibly integrated system in AWS I've used, yet it feels tucked away. While this example launched, I had time to think about how this method is a much better way to get into AWS. Don't start with EC2. Don't start with Cloud Formation. Start with EB, because you get to experience the performance of AWS yet save yourself days spent getting things to work.

The Author

Dan Frost is Technical Director of 3ev.com, cloud hosting consultants and web developers based in London and Brighton, UK. Dan has been building cloud hosting and writing and talking about the cloud since before it was trendy. Since he spun up his first AWS instance, he's been trying out new services and finding ways of getting more out of hardware, without actually owning any of it.

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs



Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>
	</a>

<hr>		    
			</div>
		    		</div>

		<div class=