Deploy and Monitor an Application from the Command Line

With Amazon Elastic Beanstalk

In this step-by-step tutorial, you will use the Elastic Beanstalk Command Line Interface to deploy and monitor an application. This is part two of a two-part series. You will need to complete the Set up the Elastic Beanstalk CLI to 10-minute tutorial before proceeding with this tutorial.

Elastic Beanstalk is a service used to deploy, manage, and scale web applications and services. You can use Elastic Beanstalk from the Amazon Web Services Management console or from the command line using the Elastic Beanstalk Command Line Interface (Elastic Beanstalk CLI).

With the Elastic Beanstalk CLI you can issue commands to the Elastic Beanstalk service using a terminal interface. You can use the Elastic Beanstalk CLI as part of your everyday development, management, and testing cycle.

During the second part of this two-part tutorial, you will create a new sample application and deploy it to the Amazon Web Services cloud using the Elastic Beanstalk CLI. Then you will monitor the application. Finally, you will terminate your application and delete the resources created during the tutorial.

Manage Your Amazon Web Services Resources


Step 1. Setup your application

In this step, you will setup an Elastic Beanstalk application directory.


a.  Using your command line, create a new folder called sample-app to use as your working directory and navigate into the sample-app folder.

  • Windows
  • md sample-app
    cd sample-app
  • MacOS
  • mkdir sample-app
    cd sample-app
  • Linux
  • mkdir sample-app
    cd sample-app

b. Using your command line, setup a new Elastic Beanstalk application by entering the following command:

eb init

c. You will be prompted to select a Region you'd like to deploy the application in. Select a region near you.

~/sample-app $ eb init
Select a default region
1) us-east-1 : US East (N. Virginia)
2) us-west-1 : US West (N. California)
3) us-west-2 : US West (Oregon)
4) eu-west-1 : EU (Ireland)
5) eu-central-1 : EU (Frankfurt)
6) ap-south-1 : Asia Pacific (Mumbai)
7) ap-southeast-1 : Asia Pacific (Singapore)
8) ap-southeast-2 : Asia Pacific (Sydney)
9) ap-northeast-1 : Asia Pacific (Tokyo)
10) ap-northeast-2 : Asia Pacific (Seoul)
11) sa-east-1 : South America (Sao Paulo)
12) cn-north-1 : China (Beijing)
13) us-east-2 : US East (Columbus)
14) ca-central-1 : Canada (Central)
15) eu-west-2 : EU (London)
(default is 3): 3

d. Next you will be prompted for user credentials. Use the Access key ID and Secret access key values from the credentials.csv file that you downloaded in part one of the tutorial.

You have not yet set up your credentials or your credentials are incorrect
You must provide your credentials.
(aws-access-id): AKIAJOUAASEXAMPLE
(aws-secret-key): 5ZRIrtTM4ciIAvd4EXAMPLEDtm+PiPSzpoK

e. Now select a platform to use. You can choose Node.js, PHP, Python, Ruby, IIS, Go, or Java for this tutorial. Type the number that corresponds to your choice and press Enter.

Select a platform.
1) Node.js
2) PHP
3) Python
4) Ruby
5) Tomcat
6) IIS
7) Docker
8) Multi-container Docker
9) GlassFish
10) Go
11) Java
(default is 1): 1

f. You won't need to SSH into your instances for this tutorial. For the "Do you want to set up SSH for your instances?" prompt, answer No. This concludes the setup of your application.

Do you want to set up SSH for your instances?
(y/n): n

This concludes the setup of your application. 


Step 2. Deploy your application

In this step, you will create and deploy a sample application on Elastic Beanstalk using the CLI. Your sample application will be deployed to one Amazon EC2 instance in an Auto Scaling group and use an Elastic Load Balancing load balancer.


a. Using your command prompt, use the Elastic Beanstalk CLI to create a setup of Amazon Web Services Resources necessary to run your application by running the following command:

eb create

b. When prompted to "Enter Environment Name", press Enter to use the default name.

Enter Environment Name
(default is sample-app-dev):

c. DNS names for Elastic Beanstalk applications have to be unique, so you will need to come up with one for your sample application. If you are having a creativity challenged moment, using "sample-app" in combination with your initials often works to create a unique name. When prompted to "Enter DNS CNAME prefix" type in a unique DNS name for your application and press Enter.

Enter DNS CNAME prefix
(default is sample-app-dev): dwarf-star-umbrella-ear

d.  Next you will be prompted to select a Load Balancer type. Choose Enter to accept the default, which is the Classic load balancer. If you'd like to comparison of these three options for reference, see Comparison of Elastic Load Balancing Products.

Select a load balancer type
1) classic
2) application
3) network
(default is 1): 1

e.  When prompted to specify or create an Elastic Beanstalk service role, press Enter to have Elastic Beanstalk create one for you. This prompt only shows up the first time you use Elastic Beanstalk.

2.0+ Platforms require a service role. We will attempt to create one for you. You can specify your own role using the --service-role option.
Type "view" to see the policy, or just press ENTER to continue:

f.  As this process proceeds, the Elastic Beanstalk CLI will output progress events to the command line. The Elastic Beanstalk CLI will warn you that it is creating a sample application for you. Then it will create the Amazon Web Services resources to run the application, and then deploy the application to those resources.

WARNING: The current directory does not contain any source code. Elastic Beanstalk is launching the sample application instead.

g. When you see "INFO: Successfully Launched Environment:" the deployment process has completed.

 


Step 3. Monitor your application

In this step, you will confirm the deployment of your sample application and monitor the health of your application using the Elastic Beanstalk CLI.


a.   Using the terminal, open your live application in a browser by entering the following command:

eb open

This page is for the Node.js sample application. If you picked a different platform, your application may look different.

( click to enlarge )


b.  To view the status of the application the Elastic Beanstalk CLI has created for you, enter the following command:

eb status

( click to enlarge )


c.  To view the health of the computing resources the Elastic Beanstalk CLI has created for you, enter the following command:

eb health

( click to enlarge )


Step 4. Terminate your application

In this step, you will terminate your sample application using the Elastic Beanstalk CLI. Terminating resources that are not actively being used reduces costs and is a best practice.


a. Using the terminal, terminate your application and its associated resources by entering the following command:


eb terminate --all

Then type in the name of your application. The Elastic Beanstalk CLI will now delete the running resources and application and output the events to the command line. When the termination is complete the Elastic Beanstalk CLI will output:

INFO: The application has been deleted successfully.

Congratulations!

Congratulations, you have setup an application, then deployed it using the Elastic Beanstalk Command Line Interface. You should use the Elastic Beanstalk CLI to deploy and manage applications whenever you want the power of Elastic Beanstalk from the command line.



Was this tutorial helpful?