The Cloud Verse

Subscribe
cloud

Ultimate guide to Elastic Beanstalk

Updated On Mar 12, 2023

Learn concepts, features, alternatives and strategies to deploy scalable, highly available web applications on Elastic Beanstalk


AWS Elastic Beanstalk is Platform as a service (PaaS) provided by AWS for quickly deploying, managing, and scaling web applications. If you don’t know about Platform as a Service, you go through this cloud computing post.


You just need to provide the source code and elastic beanstalk automatically handles the details of capacity provisioning, load balancing, scaling, and application health monitoring.


In this guide, we'll go through some important Concepts, Features of Elastic Beanstalk so that you can use them for your next project.


Concepts of Elastic Beanstalk


Applications


An elastic beanstalk application can contain one or more environments.


Application environments


Beanstalk environment is nothing but a collection of AWS resources that runs a version of an application. Each environment can be configured independently.


Application Version


A version is a specific release of an application. A version can include code, configuration files, and dependencies.


AWS Elastic beanstalk features


Monitoring


With application health monitoring, beanstalk checks whether the target instance is healthy. In a load-balanced environment, beanstalk leverages load-balancing health checks which continuously send requests to the health check URL. If it finds an unhealthy instance, it stops sending traffic to it.


You can use the beanstalk console for monitoring the environment's health, but the detailed monitoring is done from Cloudwatch.


Application Updates


Immutable Deployments: Every deployment in the beanstalk environment is immutable which ensures that the environment is updated safely. This can be used to roll back the application to the previous version if required.


Managed platform updates: AWS periodically releases the latest updates for the platforms. You can configure beanstalk to automatically apply the new platform version when it is available along with a notification in case the update fails.


Supported Platforms


AWS Elastic Beanstalk supports deploying applications written in many popular languages and frameworks.


  • Docker
  • Go
  • Java SE
  • Tomcat
  • .NET core on Linux
  • .NET on Windows Server
  • PHP
  • Python
  • Ruby

Scalability


Beanstalk provides the following environment configurations:


  • Single Instance: In a single instance configuration, beanstalk provisions a single EC2 instance with the static IP address attached to it. It is very easy to scale up or scale down the instance and beanstalk will take care of replacing the underlying VM, pointing the CNAME to it.
  • High Availability: In a high availability configuration, beanstalk provisions an elastic load balancer along with an auto-scaling group. This is a truly scalable environment as resources (EC2 instances) can be added or removed based on the load.

You can always switch from a single instance to a high-availability configuration with just a couple of clicks. This ultimately helps users and businesses to save on costs.


Environment Customization


Configuration files: Beanstalk allows you to specify the configuration files which can be used to define environment variables, database connections, VPC, etc. This also helps in declaring the infrastructure as source code.


Software packages: By default, beanstalk supports a range of pre-configured software packages for the supports but you can customize them by using shell commands in the configuration files. You can also configure cloudwatch logging, x-ray tracing, etc.


Instance types: As we know, beanstalk spins up EC2 instances under the hood when deployed. So it supports various ranges of EC2 instance types. Additionally, it allows us to specify spot instances to reduce the cost.


Load balancer settings: Beanstalk provisions an application load balancer for high-availability environments. You can configure the load balancers settings, such as SSL certificates, health checks, and listener rules.


By default, beanstalk provisions a load balancer per environment. But if you want to use a single load balancer across multiple environments, then it can be done by manually provisioning the load balancer outside of the beanstalk and referring it to the environment configuration.


Auto scaling policies: In high availability, beanstalk creates an auto-scaling group. You can configure the scaling policies based on metrics such as CPU utilization, and request latency or use scheduled scaling.


Security settings: You can configure an SSH key pair that will be applied to the EC2 instance, VPC security group, Subnet in which the instance will be created, etc. By default beanstalk uses the default vpc but you can specify the custom vpc as well. You can use this tool for generating subnets.


Integrations


Beanstalk provides direct integrations with multiple AWS services. These are as follows


CloudWatch: All logs from the server log files can be sent to the cloudwatch which can be used for debugging and troubleshooting purposes.


X-ray: Enabling X-ray tracing helps in identifying errors or latency issues with the environment.


RDS: Beanstalk supports provisioning the RDS instance similar to an EC2 instance However, it is not recommended as the lifecycle of the RDS instance will be tied with the beanstalk environment. So deleting the environment will lead to the deletion of RDS instances.


s3: Beanstalk uses an s3 bucket to store the deployable code artifacts.


Elastic Beanstalk Environment


Web Server Environment


Web server environments are meant to run web applications and APIs as they have a public-facing endpoint.


Worker Environment


Worker environment is meant to run such as processing messages from a message queue or running batch jobs. This environment can be used for decoupling the background processes such as sending the email etc.


In worker environments, beanstalk deploys SQS demon along with the application source code which continuously polls messages from the SQS queue. As soon as the daemon receives the message, it sends a POST request to the application code.


If the application returns 200 status codes, the message is deleted from the queue, else the message is sent back to the queue so that it can be processed again.


This approach works for processing messages from the queue, however, it is not recommended due to fewer configurations available to optimally process messages from the queue.


Deployments with Elastic Beanstalk


All at once


It deploys the new version of your application to all instances in your environment at once, stopping the current version and starting the new one. Since it is replacing all of the instances simultaneously, it is faster but it can result in downtime as well.


Rolling


This strategy deploys the new version of your application to a subset of instances at a time while leaving the other instances running the current version. This strategy can be slower than the "All at Once" strategy, but it reduces the impact of downtime. You can read more about rolling deployments.


Immutable


This strategy creates a new set of instances running the new version of your application and then swaps them with the old instances. This strategy can be slower than the other strategies, but it eliminates downtime and allows you to roll back to the previous version easily.


Blue/Green


This strategy creates a new environment running the new version of your application and then swaps it with the old environment. This strategy can be slower than the other strategies, but it allows you to test the new version of your application in a production-like environment before swapping it with the old environment.


How to Deploy web applications to Elastic Beanstalk


For the purpose of the blog post, we will just deploy a sample web application on beanstalk


Before deploying the beanstalk application, make sure that you have an IAM instance profile created for the EC2 instance.


  • Go to Beanstalk Page.
  • Click on Create Application.
  • Select Web Server Environment as the environment tier.
  • Provide the appropriate name for the application.
  • Select Managed Platform with Platform version 3.8
  • In the application code, select Sample Application.
  • Select Single Instance as Presets.
  • Click on Next.
  • Click on Skip to review.
  • Click on Submit.
  • It will take about 10 minutes to provision the environment.

Elastic Beanstalk vs Cloudformation


Beanstalk allows us to provide the resources based on the configuration files. But these are very specific to only a set of AWS services such as S3, RDS, EFS, etc.


But cloud formation is a general IaC (Infrastructure as Code) framework that can be utilized to create any AWS resources in an automated way.


Elastic Beanstalk vs ECS


ParameterBeanstalkECS
ServiceBeanstalk is PaaS (Platform as a Service)ECS is CaaS (Container as a Service)
Use CasesMainly meant to deploy web applications. Preferred for monolithic applications like WordPress, Django, etc.ECS can be used to deploy web apps, batch jobs, pipelines, etc. Preferred for microservices applications etc.
OperationsBeanstalk provides managed platform updates so AWS manages/patches the underlying OS of the EC2 instance.In the case of ECS, you have to manage/patch the underlying OS of the EC2 instance including updating the ECS Agent.
FlexibilityLess flexibilityMore flexibility

Elastic Beanstalk CLI


AWS provides eb cli to quickly deploy applications on elastic beanstalk using the command line. The configurations which are available in the console are also available through eb cli.


Elastic Beanstalk Pricing


There is no cost associated with the elastic beanstalk. But AWS will charge you based on the resources provisioned by the beanstalk environment such as Load Balancers, S3 Buckets, EC2 instances, etc.


Elastic Beanstalk Alternatives


Google App Engine


If you are looking for an alternative to beanstalk in GCP, then it is the App engine. App Engine is a managed service from GCP to deploy and scale web apps.


Azure App Service


Azure app service is a beanstalk alternative in Azure.


AWS App Runner


App Runner is the beanstalk alternative from AWS only. You just need to provide the container image and the app runner will do automatic provisioning of the underlying resources.


FAQs


What is Elastic beanstalk vs EC2?


EC2 is an Infrastructure as a Service (IaaS) where you get the VM based on the CPU / Memory that you specify. In that VM, you can configure any applications, software, etc and you have to manage the OS.


Beanstalk is a managed service that is specific to running web applications on AWS.


Is Elastic Beanstalk PaaS or IaaS?


Elastic Beanstalk is a Platform as a Service (PaaS)


Dhairyasheel Sutar

I am an Experienced Engineer with a strong IT background and a passion for technology exploration. My journey started in college, where I went into web development, AI/ML, and more. I've worked with GCP and AWS, holding certifications in both and being proficient in Kubernetes, Docker, and Terraform. This blog is where I write about my technical expertise.

© 2023 The Cloud Verse. All rights reserved

LinkedInGithub

Links

AboutPortfolio

Stay up to date