|« PreviousNext »|
|Did this page help you? Yes | No | Tell us about it...|
The following diagram illustrates a typical software development life cycle including deploying your application to AWS Elastic Beanstalk.
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 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 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.
Eb is a command line interface that enables you to deploy applications quickly and more easily using Git. Eb is available as part of the Elastic Beanstalk command line tools package. Follow the steps below to install eb and initialize your Git repository.
To install eb, its prerequisite software, and initialize your Git repository
Install the following software onto your local computer:
Download and unzip the Elastic Beanstalk command line tools package at the AWS Sample Code & Libraries website.
Git 1.6.6 or later. To download Git, go to http://git-scm.com/.
Windows 7 and Windows Server 2008 R2 come with PowerShell 2.0. If you are running an earlier version of Windows, you can download PowerShell 2.0. Visit http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx for more details.
Initialize your Git repository.
git init .
After installing eb 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 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.
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.
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.
|On Linux and UNIX||On Windows|
To configure AWS Elastic Beanstalk
From your directory where you created your local repository, type the following command.
When you are prompted for the access key ID, type your access key ID. To get your access key ID, see How Do I Get Security Credentials? in the AWS General Reference.
Enter your AWS Access Key ID (current value is "AKIAIOSFODNN7EXAMPLE"):
When you are prompted for the secret access key, type your secret access key. To get your secret access key, see How Do I Get Security Credentials? in the AWS General Reference.
Enter your AWS Secret Access Key (current value is "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"):
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 East (Virginia).
When you are prompted for the AWS Elastic Beanstalk application name, type the name of the application. AWS Elastic Beanstalk auto-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 quotes.
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 an AWS Elastic Beanstalk environment name (current value 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, choose an environment tier. For this example, we'll use
Available environment tiers are: 1) WebServer::Standard::1.0 2) Worker::SQS/HTTP::1.0
When you are prompted for the solution stack, type the number of the solution stack you want. For this example, we'll use 64bit Amazon Linux running PHP 5.4.
When you are prompted to create an Amazon RDS DB instance, type
n. For this example, we'll type
Create an RDS DB Instance? [y/n]:
When you are prompted to create the database from scratch or a snapshot, type your
selection. For this example, we'll use
When you are prompted to enter your RDS user master password, type your password containing from 8 to 16 printable ASCII characters (excluding /, \, and @).
Enter an RDS DB master password:
Retype password to confirm:
When you are prompted to create a snapshot if you delete the Amazon RDS DB instance, type
n. For this example, we'll
n. If you type
n, then your RDS
DB instance will be deleted and your data will be lost if you terminate your
You should see a confirmation that your AWS Credential file was successfully updated.
By default, eb sets the following default values for Amazon RDS.
Database engine — MySQL
Default version: — 5.5
Database name: — ebdb
Allocated storage — 5GB
Instance class — db.t1.micro
Deletion policy — delete
Master username — ebroot
When you are prompted to enter your instance profile name, you can choose to create a
default instance profile or use an existing instance profile. Using an instance profile enables IAM users and AWS services to
gain access to temporary security credentials to make AWS API calls. Using instance
profiles prevents you from having to store long-term security credentials on the EC2
instance. For more information about instance profiles, see Granting Permissions to Users and Services Using IAM
Roles. For this
example, we'll use
Create a default instance profile.
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
command again. When prompted, you can update your configuration options. If you want to keep
any previous settings, press the Enter key. If you want to update your
Amazon RDS DB configuration settings, you can update your
optionsettings file in the
directory, and then use the
eb update command to update your AWS Elastic Beanstalk environment.
To deploy a sample application
From your directory where you created your local repository, type the following command.
This process may take several minutes to complete. AWS Elastic Beanstalk will provide status updates during the process. If at any time you want to stop polling for status updates, press Ctrl+C. Once the environment status is Green, AWS Elastic Beanstalk will output a URL for the application. You can copy and paste the URL into your web browser to view the application.
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-east-1.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.
To investigate any issues, you can view logs. For information about viewing logs, see Working with Logs. If you need to test remotely, you can connect to your Amazon EC2 instances. For instructions on how to connect to your instance, see Listing and Connecting to Server Instances.
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.
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, 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.
To deploy to production using eb
Commit your changes.
git add . git commit -m "final checkin"
Create a branch and switch to it.
git checkout -b prodenv eb branch
When prompted, type your new environment name, and accept all settings from your previous environment.
Then launch your new environment.
Deploy your application to AWS Elastic Beanstalk.
For more information about eb and branches, see Deploying a Git Branch to a Specific 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.