The following diagram illustrates a typical software development life cycle including deploying your application to Elastic Beanstalk.
Typically, after developing and testing your application locally, you
will deploy your application to Elastic Beanstalk. At this point, your application will be live at a
URL such as http://myexampleapp-wpams3yrvj.elasticbeanstalk.com. 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>.elasticbeanstalk.com. Contact your
DNS provider to set this up. For information about how to map your root domain to your
Elastic Load Balancer, see Using Elastic Beanstalk with Amazon Route 53 to Map Your Domain to
Your Load Balancer. After you remotely test and debug your Elastic Beanstalk
application, you can then make any updates and redeploy to 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 Elastic Beanstalk using eb. If you want instructions on how to deploy a PHP application using the Elastic Beanstalk console, see Deploying Elastic Beanstalk Applications in PHP Using the Elastic Beanstalk Console.
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 .
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.
<html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html>
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.
Normally, at this point you would test your application locally before deploying to 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.
After testing your application, you are ready to deploy it to Elastic Beanstalk. Deploying requires the following steps:
Configure Elastic Beanstalk.
Deploy a sample application.
Update the sample application with your application.
When you update the sample application with your application, Elastic Beanstalk replaces the existing sample application version with your new application version in the existing environment.
init command, and 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 UNIX||In Windows|
If you are using Python 3.0, the path will include
To configure Elastic Beanstalk
From the directory where you created your local repository, type the following command:
When you are prompted for the 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).
When you are prompted for the Elastic Beanstalk application to use, type the number corresponding to the option Create new Application. 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.
y if Elastic Beanstalk correctly detected the correct platform you are using. Type
n if not, and then specify the correct platform.
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
Do you want to set up SSH for your instances? (y/n): n
Create your running environment.
When you are prompted for the Elastic Beanstalk environment name, type the name of the environment. 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.
When you are prompted to provide a CNAME prefix, type the CNAME prefix you want to use. 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 Elastic Beanstalk, you are ready to deploy a sample application.
If you want to update your Elastic Beanstalk configuration, you can use the
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
Type the following command.
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>@git.elasticbeanstalk.us-west-2.amazon.com/helloworld/helloworldenv 44c7066..b1f11a1 master -> master
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.
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
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 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 Elastic Beanstalk environment.
You can use the AWS Management Console, CLI, or APIs to manage your 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.
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:
Commit your changes
Create a branch
Create and launch your new environment
Deploy your application to your new production environment
When you update your application using EB CLI, 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
Commit your changes.
git add . git commit -m "final checkin"
Create a branch and switch to it.
git checkout -b prodenv eb use prod
When prompted, type your new environment name, and accept all settings from your previous environment.
When you are ready, deploy your new application version to Elastic Beanstalk.
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.