Deploy containers by using Elastic Beanstalk - AWS Prescriptive Guidance

Deploy containers by using Elastic Beanstalk

Created by Thomas Scott (AWS) and Jean-Baptiste Guillois (AWS)

Code repository: Cluster Sample App

Environment: Production

Technologies: Containers & microservices; CloudNative; Modernization

AWS services: AWS Elastic Beanstalk

Summary

On the Amazon Web Services (AWS) Cloud, AWS Elastic Beanstalk supports Docker as an available platform, so that containers can run with the created environment. This pattern shows how to deploy containers using the Elastic Beanstalk service. The deployment of this pattern will use the web server environment based on the Docker platform.

To use Elastic Beanstalk for deploying and scaling web applications and services, you upload your code and the deployment is automatically handled. Capacity provisioning, load balancing, automatic scaling, and application health monitoring are also included. When you use Elastic Beanstalk, you can take full control over the AWS resources that it creates on your behalf. There is no additional charge for Elastic Beanstalk. You pay only for the AWS resources that are used to store and run your applications.

This pattern includes instructions for deployment using the AWS Elastic Beanstalk Command Line Interface (EB CLI) and the AWS Management Console.

Use cases

Use cases for Elastic Beanstalk include the following: 

  • Deploy a prototype environment to demo a frontend application. (This pattern uses a Dockerfile as the example.)

  • Deploy an API to handle API requests for a given domain.

  • Deploy an orchestration solution using Docker-Compose (docker-compose.yml is not used as the practical example in this pattern).

Prerequisites and limitations

Prerequisites 

  • An AWS account

  • AWS EB CLI locally installed

  • Docker installed on a local machine

Limitations 

  • There is a Docker pull limit of 100 pulls per 6 hours per IP address on the free plan.

Architecture

Target technology stack 

  • Amazon Elastic Compute Cloud (Amazon EC2) instances

  • Security group

  • Application Load Balancer

  • Auto Scaling group

Target architecture 

Architecture for deploying containers with Elastic Beanstalk.

Automation and scale

AWS Elastic Beanstalk can automatically scale based on the number of requests made. AWS resources created for an environment include one Application Load Balancer, an Auto Scaling group, and one or more Amazon EC2 instances. 

The load balancer sits in front of the Amazon EC2 instances, which are part of the Auto Scaling group. Amazon EC2 Auto Scaling automatically starts additional Amazon EC2 instances to accommodate increasing load on your application. If the load on your application decreases, Amazon EC2 Auto Scaling stops instances, but it keeps at least one instance running.

Automatic scaling triggers

The Auto Scaling group in your Elastic Beanstalk environment uses two Amazon CloudWatch alarms to initiate scaling operations. The default triggers scale when the average outbound network traffic from each instance is higher than 6 MB or lower than 2 MB over a period of five minutes. To use Amazon EC2 Auto Scaling effectively, configure triggers that are appropriate for your application, instance type, and service requirements. You can scale based on several statistics including latency, disk I/O, CPU utilization, and request count. For more information, see Auto Scaling triggers.

Tools

AWS services

  • AWS Command Line Interface (AWS CLI) is an open-source tool that helps you interact with AWS services through commands in your command-line shell.

  • AWS EB Command Line Interface (EB CLI) is a command-line client that you can use to create, configure, and manage Elastic Beanstalk environments.

  • Elastic Load Balancing distributes incoming application or network traffic across multiple targets. For example, you can distribute traffic across Amazon Elastic Compute Cloud (Amazon EC2) instances, containers, and IP addresses in one or more Availability Zones.

Other services

  • Docker packages software into standardized units called containers that include libraries, system tools, code, and runtime.

Code

The code for this pattern is available in the GitHub Cluster Sample Application repository.

Epics

TaskDescriptionSkills required

Clone the remote repository.

  • To clone the repository, run the command git clone https://github.com/aws-samples/cluster-sample-app.git.< /p>

App developer, AWS administrator, AWS DevOps

Initialize the Elastic Beanstalk Docker project.

  1. Create a file called aws.json at the root.

  2. In the aws.json file, add the following code.

    {    "AWSEBDockerrunVersion":"1",    "Image":{       "Name":"cluster-sample-app"    },    "Ports":[       {          "ContainerPort":80,          "HostPort":8080       }    ] }
  3. Run the command eb init -p docker at the root of the project.

App developer, AWS administrator, AWS DevOps

Test the project locally.

  1. Run the command eb local run at the root of the project.

  2. Test the application by navigating to http://localhost.

App developer, AWS administrator, AWS DevOps
TaskDescriptionSkills required

Run deployment command

  1. Run the command eb create docker-sample-cluster-app at the root of the project.

App developer, AWS administrator, AWS DevOps

Access the deployed version.

After the deployment command has finished, access the project using the eb open command.

App developer, AWS administrator, AWS DevOps
TaskDescriptionSkills required

Deploy the application by using the browser.

  1. Open the console.

  2. Navigate to the Elastic Beanstalk console.

  3. Choose Create Application.

  4. For the Application Name, enter Cluster-Sample-App.

  5. Choose Docker as the platform.

  6. Choose Upload your code.

  7. Choose your local .zip file (in the root of the cloned project) or a public Amazon Simple Storage Service (Amazon S3) URL.

App developer, AWS administrator, AWS DevOps

Access the deployed version.

After deployment, access the deployed application, and choose the URL provided.

App developer, AWS administrator, AWS DevOps

Related resources

Additional information

Advantages of using Elastic Beanstalk

  • Automatic infrastructure provisioning

  • Automatic management of the underlying platform

  • Automatic patching and updates to support the application

  • Automatic scaling of the application

  • Ability to customize the number of nodes

  • Ability to access the infrastructure components if needed

  • Ease of deployment over other container deployment solutions