Elastic Beanstalk with Autoscaling
This Blog has moved from Medium to blogs.tensult.com. All the latest content will be available there. Subscribe to our newsletter to stay updated.
What is Elastic Beanstalk?
Elastic Beanstalk provides developers and system administrators an easy, fast way to deploy and manage their applications without having to worry about AWS infrastructure. You simply upload your application, and Elastic Beanstalk automatically handles the details of capacity provisioning, load balancing, scaling, and application health monitoring.
Why Elastic Beanstalk?
1) Reduce the time to set up the deployment environment
Elastic Beanstalk console is a central place to configure AWS services. This involves setting up programming environments, load balancers, autoscale etc with minimum administrative efforts.
2) Implement innovative ideas
Since Elastic Beanstalk supports multiple application environments like PHP, Java, Node.js etc, the developer can port the code to the new environment without learning about infrastructure services, which enables them to put forward their ideas to the management.
3) Better productivity
Developer doesn't need to wait for a system administrator or a cloud engineer to set up the environment for his deployment. They can focus only the software development.
4) Better focus on building the application stack
Elastic Beanstalk console allows you to set up the application environment chosen at AWS console without logging on the instances.
Applications and Environments
An Elastic Beanstalk application is a logical collection of Elastic Beanstalk components, including environments, versions, and environment configurations. In Elastic Beanstalk an application is conceptually similar to a folder.
An environment is a version that is deployed onto AWS resources. You can use the AWS Management Console to upload an updated source bundle and deploy it to your AWS Elastic Beanstalk environment or redeploy a previously uploaded version. Each environment can have a completely different configuration if required.
Configuring and Creating an Environment
Setting up an application and environment in Elastic Beanstalk is a straight forward process. The first step is to define the application, then within an application, we define environments. These are typically things like questions and answers. Once you have an environment configured, up and running with a sample application you can go ahead and publish your application to it. Now it’s a case of changing the various configuration options to accommodate your environment requirement. You may need to consider things such as for instance types, VPC configurations, security groups, monitoring, auto-scaling and load balancing.
AutoScaling with Elastic Beanstalk
Elastic Beanstalk Web servers are provisioned behind a load balancer and handle end-user requests, Elastic Beanstalk provides basic auto-scaling based on metrics collected from the underlying instances. We use Average CPU utilization as a metric for autoscaling.
1) Launch Elastic Beanstalk service from AWS Console.
2) Click Actions-> Create an environment to create an environment within the application.
3) Select the Web server environment.
4) Create New environment window opens. In the domain filed enter a name and click check availability. The name is unique within the region
5) Select the Preconfigured platform from the list. I have selected PHP here. Also, select the application code. I selected a sample application here. You can also select upload your code to deploy your own code. Click Configure more options to accommodate autoscaling and load balancing.
6) In the configure application window select Low cost or custom configuration against configuration presets. We will select only minimal parameters required to set up an environment, which had load balancing and auto-scaling enabled.
7) In Modify instances page select the security groups. Make sure the web service related ports are allowed in the selected security group. Change other settings based on the requirement.
8) In modify the capacity page, select the environment type load balanced. We want to spin up to a maximum of 3 instances based on the metric Average CPU utilization. It Spins up one instance when Average CPU utilization crosses 50% and terminates when it comes down to 20%.
9) In Modify load balancer page select load balancer type. I have selected a classic one here. Port number selected as 80. I have selected only the minimum parameters here. Select the parameters based on your environment.
10) In modify security select EC2 key pair. This is very important if you want to ssh to the instances created
11) In the modify Network page select your VPC, Load balancer subnet, instance subnets, and other required parameters. Save the configuration to launch back to the configuration application window.
12) In configuration application window click create an environment. It takes around 3 minutes to create an environment
13) Click the URL in your environment window to open up the sample application.
14) Log in to the instance created and do the stress test to verify that autoscale works.