Deploy and Monitor an Application from the Command Line

With AWS 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 (EB) is a service used to deploy, manage, and scale web applications and services. You can use Elastic Beanstalk from the AWS Management console or from the command line using the Elastic Beanstalk Command Line Interface (EB CLI).

With the EB CLI you can issue commands to the EB service using a terminal interface. You can use the EB 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 AWS cloud using the EB CLI. Then you will monitor the application. Finally, you will terminate your application and delete the resources created during the tutorial.

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 EB 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 EB CLI to create a setup of AWS 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 EB 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.

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.

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 EB CLI will output progress events to the command line. The EB CLI will warn you that it is creating a sample application for you. Then it will create the AWS 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 EB 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 EB CLI has created for you, enter the following command:

eb status

( click to enlarge )

c. To view the health of the computing resources the EB 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 EB 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 EB CLI will now delete the running resources and application and output the events to the command line. When the termination is complete the EB 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 EB CLI to deploy and manage applications whenever you want the power of Elastic Beanstalk from the command line.