AWS News Blog

AWS Elastic Beanstalk – Simplified Command Line Access with EB

I would like to welcome eb (pronounced ee-bee) to the family of Elastic Beanstalk command line tools! Eb simplifies the development and deployment tasks from the terminal on Linux, Mac OS, and Microsoft Windows. Getting started using Elastic Beanstalk from the command line is now as simple as:

  • eb init to set up credentials, choose the AWS Region, and the Elastic Beanstalk solution stack (operating system + application server + language environment).
  • eb start to create the Elastic Beanstalk application and launch an environment within it.
  • git aws.push to deploy code.

You can give eb a try by downloading the latest Elastic Beanstalk Command Line Tools. To learn more about eb, visit the AWS Elastic Beanstalk Developer Guide.

Here is how I use it to manage my Elastic Beanstalk applications…

Get Started
First, download the updated Elastic Beanstalk Command Line Tools and unzip it to a directory on disk. For quick access to the eb command, I recommend that you add this directory to your PATH. You are all set up and ready to go!

Create Your Application
In your applications directory, initialize your Git repository and run the following commands to create an Elastic Beanstalk application:

<devserver >: git init
Initialized empty Git repository in /Users /jeff /blog /.git

<devserver>: eb init
To get your AWS Access Key ID and Secret Access Key, visit “https://aws-portal.amazon.com/gp/aws/securityCredentials”.
Enter your AWS Access Key ID: AB…78
Enter your AWS Secret Access Key: abcd…1234
Select an AWS Elastic Beanstalk service region.
Available service regions are:
1) “US East (Virginia)”
2) “EU West (Ireland)”
3) “Asia Pacific (Tokyo)”
Select (1 to 3): 1
Enter an AWS Elastic Beanstalk application name (auto-generated value is “jeffblog”):
Enter an AWS Elastic Beanstalk environment name (auto-generated value is “jeffblog-env”):
Select a solution stack.
Available solution stacks are:
1) “32bit Amazon Linux running Tomcat 7”
2) “64bit Amazon Linux running Tomcat 7”
3) “32bit Amazon Linux running Tomcat 6”
4) “64bit Amazon Linux running Tomcat 6”
5) “32bit Amazon Linux running PHP 5.3”
6) “64bit Amazon Linux running PHP 5.3”
7) “64bit Windows Server 2008 R2 running IIS 7.5”
Select (1 to 7): 6
Successfully updated AWS Credential file at “C:\Users\jeff\.elasticbeanstalk\aws_credential_file”.

<devserver>: eb start
Now creating application “jeffblog”.
Waiting for environment “jeffblog-env” to launch.
2012-06-26 21:23:05     INFO    createEnvironment is starting.
2012-06-26 21:23:14     INFO    Using elasticbeanstalk-eu-west-1123456789012 as Amazon S3 storage bucket for environment data.
2012-06-26 21:23:15     INFO    Created Auto Scaling launch configuration named: awseb-jeffblog-env-65rxDnIDWV.
2012-06-26 21:23:16     INFO    Created load balancer named: awseb-jeffblog-env.
2012-06-26 21:23:16     INFO    Created Auto Scaling group named: awseb-jeffblog-env-Bub8kxJmPP.
2012-06-26 21:23:17     INFO    Created Auto Scaling trigger named: awseb-jeffblog-env-Bub8kxJmPP.
2012-06-26 21:23:19     INFO    Waiting for an EC2 instance to launch.
2012-06-26 21:24:05     INFO    Adding EC2 instances to the load balancer. This may take a few minutes.
2012-06-26 21:27:00     INFO    Application available at jeffblog-env-3tqewduwvb.elasticbeanstalk.com.
2012-06-26 21:27:04     INFO    Successfully launched environment: jeffblog-env
Application is available at “jeffblog-env-3tqewduwvb.elasticbeanstalk.com”.

In the example above, eb init walks you through a few questions and configures your settings so you can easily create and manage your application. It also configures your Git repository so you can directly push to Elastic Beanstalk. The command eb start creates the resources and launches a sample application on Elastic Beanstalk. The application is accessible at the URL shown above.

Deploy Your Code
To deploy your code to Elastic Beanstalk, you simply use git aws.push like this:

<devserver >: echo “<html><body><h1><?=’Hello eb!’?></h1></body></html>” > index.php

<devserver>: git add index.php

<devserver>:  git commit m v1
[master (root-commit) 23159c7] v1
 1 files changed, 1 insertions(+), 0 deletions()
 create mode 100644 index.php

<devserver>:  git aws.push
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 249 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
To https://abcd:1234@git.elasticbeanstalk.us-east-1.amazonaws.com/repos/6a656666626c6f67/jeffblog-env
 * [new branch]      HEAD –> master

To test your uploaded application, browse to the applications URL:

Update your Configuration Settings
Eb stores configuration settings in a file called .optionsettings inside the .elasticbeanstalk directory. To update your configuration settings, simply open the .optionsettings file, make a change, and then run eb update.

For example, to update my instance type from t1.micro to m1.small, I simply change the value of instancetype to m1.small and then run the following commands:

 

<devserver >: eb update
Updating environment “jeffblog-env”. This may take a few minutes.
2012-06- 26 21: 31: 41     INFO    Switched configuration attached to environment.
Environment “jeffblog-env” has been successfully updated.

Get Information about your Application
To get information about your Elastic Beanstalk application, you can use the eb status command:

<devserver >: eb status
URL     : jeffblog-env-3tqewduwvb.elasticbeanstalk.com
Status  : Ready
Health  : Green

Cleaning Up
Eb
provides 2 mechanisms to clean up: eb stop and eb delete.

The eb stop command deletes the AWS resources that are running your application (such as the ELB and the EC2 instances). It however leaves behind all of the application versions and configuration settings that you had deployed, so you can quickly get started again. Eb stop is ideal when you are developing and testing your application and dont need the AWS resources running over night. You can get going again by simply running eb start.

The eb delete command deletes the AWS resources as well as all application versions and configuration settings associated with your application. Eb delete is ideal when youre cleaning up a test application and want to start working on a new application from scratch.

<devserver >: eb stop
Are you sure? [y /n ]:y
Stopping environment “jeffblog-env”. This may take a few minutes.
$   2012-06- 26 21: 36: 48     INFO    terminateEnvironment is starting.
2012-06- 26 21: 36: 53     INFO    Deleted Auto Scaling trigger named: awseb-jeffblog-env-Bub8kxJmPP.
2012-06- 26 21: 36: 55     INFO    Set Auto Scaling group named: awseb-jeffblog-env-Bub8kxJmPP to zero ec2 instances.
2012-06- 26 21: 36: 58     INFO    Deleted load balancer named: awseb-jeffblog-env.
2012-06- 26 21: 37:02     INFO    Terminating Environment jeffblog-env.
2012-06- 26 21: 37:05     INFO    Waiting for Auto Scaling groups to terminate ec2 instances.
2012-06- 26 21: 38: 12     INFO    Waiting for Auto Scaling groups to terminate ec2 instances.
2012-06- 26 21: 39:04     INFO    Waiting for Auto Scaling groups to terminate ec2 instances.
2012-06- 26 21: 39:04     INFO    Auto Scaling groups terminated all ec2 instances
Environment “jeffblog-env” has been successfully stopped.

As you can see, eb gives you the power to set up, manage, and update your Elastic Beanstalk applications from the command line. Give it a try and let me know what you think.

Jeff;

Jeff Barr

Jeff Barr

Jeff Barr is Chief Evangelist for AWS. He started this blog in 2004 and has been writing posts just about non-stop ever since.