AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)
Did this page help you?  Yes | No |  Tell us about it...
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.

Develop, Test, and Deploy

The following diagram illustrates a typical software development life cycle including deploying your application to AWS Elastic Beanstalk.

Software Development Life Cycle

Typically, after developing and testing your application locally, you will deploy your application to AWS Elastic Beanstalk. At this point, your application will be live at a URL such as Because your application will be live, you should consider setting up multiple environments, such as a testing environment and a production environment. You can point your domain name to the Amazon Route 53 (a highly available and scalable Domain Name System (DNS) web service) CNAME <yourappname> Contact your DNS provider to set this up. For information about how to map your root domain to your Elastic Load Balancer, see Using AWS Elastic Beanstalk with Amazon Route 53 to Map Your Domain to Your Load Balancer. After you remotely test and debug your AWS Elastic Beanstalk application, you can then make any updates and redeploy to AWS Elastic Beanstalk. After you are satisfied with all of your changes, you can upload your latest version to your production environment. The following sections provide more details explaining each stage of the software development life cycle.

This section walks you through the steps to deploy a PHP application to AWS Elastic Beanstalk using eb. If you want instructions on how to deploy a PHP application using the Elastic Beanstalk console, see Deploying AWS Elastic Beanstalk Applications in PHP Using the Elastic Beanstalk Console.

Get Set Up

EB CLI is a command line interface that you can use with Git to deploy applications quickly and more easily. EB is available as part of the Elastic Beanstalk command line tools package. For instructions to install EB CLI, see Getting Set Up with EB Command Line Interface (CLI) 3.x.

Initialize your Git repository. After you run the following command, when you run eb init, EB CLI will recognize that your application is set up with Git.

git init .

Develop Locally

After installing EB CLI on your local computer, you use the Git command line as you normally would to create your local repository and add and commit changes. You create your PHP application as you normally would with your favorite editor. If you don't already have a PHP application ready, you can use a simple "Hello World" application. Type the following program into your favorite editor, and save it as a PHP file.

  <title>PHP Test</title>
 <?php echo '<p>Hello World</p>'; ?> 

Next, create a new local repository, add your new program, and commit your change.

git add index.php
git commit -m "initial check-in"			


For information about Git commands, go to Git - Fast Version Control System.

Test Locally

Normally, at this point you would test your application locally before deploying to AWS Elastic Beanstalk. Suppose you find a few issues you would like to fix. Using the above "Hello World" application, add a "!" after "Hello World" and check in your changes. Update your index.php file, and then type the following commands to check in your updated file.

git add index.php
git commit -m "my second check-in"		

After you commit your changes, you should see a response similar to the following:

[master 0535814] my second check-in
1 files changed, 1 insertions(+), 1 deletions(-)		

Note the commit ID that is generated. This ID is used to generate a version label for your application.

Deploy to AWS Elastic Beanstalk

After testing your application, you are ready to deploy it to AWS Elastic Beanstalk. Deploying requires the following steps:

  • Configure AWS Elastic Beanstalk.

  • Deploy a sample application.

  • Update the sample application with your application.

When you update the sample application with your application, AWS Elastic Beanstalk replaces the existing sample application version with your new application version in the existing environment.

Use the init command, and AWS Elastic Beanstalk will prompt you to enter this information. If a default value is available, and you want to use it, press Enter.

Before you use eb, set your PATH to the location of eb. The following table shows an example for Linux/UNIX and Windows.

In Linux and UNIXIn Windows
$ export PATH=$PATH:<path to unzipped eb CLI package>/eb/linux/python2.7/

If you are using Python 3.0, the path will include python3 rather than python2.7.

C:\> set PATH=%PATH%;<path to unzipped eb CLI package>\eb\windows\

To configure AWS Elastic Beanstalk

  1. From the directory where you created your local repository, type the following command:

    eb init
  2. When you are prompted for the AWS Elastic Beanstalk region, type the number of the region. For information about this product's regions, go to Regions and Endpoints in the Amazon Web Services General Reference. For this example, we'll use US West (Oregon).

  3. When you are prompted for the AWS Elastic Beanstalk application to use, type the number corresponding to the option Create new Application. AWS Elastic Beanstalk generates an application name based on the current directory name if an application name has not been previously configured. In this example, we use HelloWorld.

    Enter an AWS Elastic Beanstalk application name (auto-generated value is "windows"): HelloWorld


    If you have a space in your application name, make sure you do not use quotation marks.

  4. Type y if AWS Elastic Beanstalk correctly detected the correct platform you are using. Type n if not, and then specify the correct platform.

  5. When prompted, type y if you want to set up Secure Shell (SSH) to connect to your instances. Type n if you do not want to set up SSH. In this example, we will type n.

    Do you want to set up SSH for your instances?
    (y/n): n
  6. Create your running environment.

    eb create
  7. When you are prompted for the AWS Elastic Beanstalk environment name, type the name of the environment. AWS Elastic Beanstalk automatically creates an environment name based on your application name. If you want to accept the default, press Enter.

    Enter Environment Name
    (default is HelloWorld-env):


    If you have a space in your application name, make sure you do not have a space in your environment name.

  8. When you are prompted to provide a CNAME prefix, type the CNAME prefix you want to use. AWS Elastic Beanstalk automatically creates a CNAME prefix based on the environment name. If you want to accept the default, press Enter.

    Enter DNS CNAME prefix
    (default is HelloWorld):

After configuring AWS Elastic Beanstalk, you are ready to deploy a sample application.

If you want to update your AWS Elastic Beanstalk configuration, you can use the init command again. When prompted, you can update your configuration options. If you want to keep any previous settings, press the Enter key.

To update the sample application with your local application

  1. Type the following command.

    eb deploy
  2. If everything worked as expected, you should see something similar to the following:

    Counting objects: 5, done.
    Delta compression using up to 4 threads.
    Compressing objects:100% (2/2), done.
    Writing objects: 100% (3/3), 298 bytes, done.
    Total 3 (delta 1), reused 0 (delta 0)
    To https://<some long string>
    	44c7066..b1f11a1	master -> master			
  3. Verify that your application has been updated by refreshing your web browser.


    The running version is updated and begins with the commit ID from your last commit.

Debug/View Logs

You can use the eb logs command to investigate any issues. If you do not specify any flags with the command, logs will be displayed in the command window. For other ways to retrieve logs using this command, see logs.

Edit the Application and Redeploy

Now that you have tested your application, it is easy to edit your application, redeploy, and see the results in moments. First, make changes to your application and commit your changes. Then deploy a new application version to your existing AWS Elastic Beanstalk environment.

git add index.php
git commit -m "my third check-in"
git aws.push		

A new application version will be uploaded to your AWS Elastic Beanstalk environment.

You can use the AWS Management Console, CLI, or APIs to manage your AWS Elastic Beanstalk environment. For more information, see Managing and Configuring Applications and Environments Using the Console, CLI, and APIs.

You can also configure Git to push from a specific branch to a specific environment. For more information, see Deploying a Git Branch to a Specific Environment.

Deploy to Production

When you are satisfied with all of the changes you want to make to your application, you can deploy it to your production environment. To deploy your application to a new environment, do the following:

  1. Commit your changes

  2. Create a branch

  3. Create and launch your new environment

  4. Deploy your application to your new production environment

When you update your application using EB CLI, AWS Elastic Beanstalk will create a new application version. For information on how to deploy an already existing application version to a new environment, see Launching New Environments. The following steps walk you through committing your new changes and then updating your environment with a new application version using EB CLI and Git.

To deploy to production using EB CLI

  1. Commit your changes.

    git add .
    git commit -m "final checkin"
  2. Create a branch and switch to it.

    git checkout -b prodenv
    eb use prod
  3. When prompted, type your new environment name, and accept all settings from your previous environment.

  4. When you are ready, deploy your new application version to AWS Elastic Beanstalk.

    eb deploy

Deploy an Existing Application Version to an Existing Environment

If you need to deploy an existing application to an existing environment, you can do so using the AWS Management Console, CLI, or APIs. You may want to do this if, for instance, you need to roll back to a previous application version. For instructions on how to deploy an existing application version to an existing environment, see Deploying Versions to Existing Environments.