ElasticBeanstalk 101

What is Elastic Beanstalk?

Elastic Beanstlak is a service for deploying and scaling web applications developed in many popular languages: Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker onto widely used application server platforms like Apache Tomcat, Nginx, PAssenger, and IIS.

Developers can focus on writing code and don't need to worry about any of the underlying infrastructure needed to run the application.

Throw some code in a zip file, elastic beanstalk configures the app. Configures web servers, RDS, etc. Similar to cloudformation, except CloudFormation is all JSON based and you upload a template. With ElasticBeanstalk, use the GUI and provision your own environment.

You upload the code and Elastic Beanstalk will handle deployment, capacity provisioning, load balancing, auto-scaling and application health.

You retain fujll control of the underlying AWS resources powering your applicatoin and you pay only for the AWS resources required to store and run your applications (e.g. EC2 instances and S3 buckets).

When you create a new Elastic Beanstalk deployment, it creates an S3 Bucket and saves the versions of your code in the S3 bucket.

  • Fastest and simplest way to deploy your application in AWS
  • Automatically scales your application up and down
  • You can select the EC2 instance type that is optimal for your application
  • You can retain fulla dminstrative control over the resources powering your application, or have ElasticBeanstalk do it for you
  • Managed Platform Updates feature automatically applies updates to your Operating System, Java, PHP, Node.js, etc.
  • Monitor and manage application health via a dashboard
  • Integrated with CloudWatch and X-Ray for performance data and metrics\

Elastic Beanstalk Exam Tips

  • Deploys and scales your web applications including the web applications server platform where required
  • Supports widely used programming technologies
    • Java, PHP, Python, Ruby, Go, Docker, .NET, Node.js
  • Supports application server platforms like Tomcat, Passenger, Puma, and IIS
  • Provisions the underlying resources for you
  • Can fully manage the EC2 instances for you or you can take full administrative control
  • Updates, monitoring, metrics, and health checks all included

LifeCycle Policy

Each time you upload a new version of your application with the Elastic Beanstalk console or the EB CLI, Elastic Beanstalk creates an application version. If you don't delete versions that you no longer use, you will eventually reach the application version limit and be unable to create new versions of that application.

You can avoid hitting the limit by applying an application version lifecycle policy to your applications. A lifecycle policy tells Elastic Beanstalk to delete application versions that are old, or to delete application versions when the total number of versions for an application exceeds a specified number.

Elastic Beanstalk applies an application's lifecycle policy each time you create a new application version, and deletes up to 100 versions each time the lifecycle policy is applied. Elastic Beanstalk deletes old versions after creating the new version, and does not count the new version towards the maximum number of versions defined in the policy.

Decoupling an RDS Database instance

When you have an RDS instance outside of your Beanstalk environment, the EC2 instances in the environment must have a configured Auto scaling group with an additional security group. The security group that you attach to your envirnoment can be the same one that is attached to your database instance, or a separate security group from which the database's security group allows ingress.

You can connect your environment to a database by adding a rule to your database's security group that allows ingress from the autogenerated security group that Beanstalk attaches to your environment's Auto Scaling group. However, doing so creates a dependency between the two security groups. When you attempt to terminate the environment, Beanstalk will be unable to delete the environment's security group because the database's security group is dependant on it.

Elastic Beanstalk CLI

If you push to deploy an updated version using a zip file, you must use the deploy command and not the update-application command.

Update-application is just used to update information about the application, i.e. the description.

Beanstalk Environment File

In Beanstalk, you can include a YAML formatted environment manifest in the root of your application source bundle to configure the encinroment name, solution stack, and environment links to use when creating your environment. An environment manifest uses the same format as Saved Configurations.

This file format includes support for environment groups. To use groups, speciify the environment name in the manifest with a + symbol at the end. When you create or update the environment, specify the group name with --group-name (AWS CLI) or --env-groupsuffix (EB CLI).

The following manifest defines a web server environment for the tutorialsdojo frontend application, with a link to a worker environment component that it is dependent upon. The manifest uses groups to allow creating multiple environments with the same source bundle:

~/tutorialsdojo/frontend/env.yaml

AWSConfigurationTemplateVersion: 1.1.0.0
SolutionStack: 64bit Amazon Linux 2015.09 v2.0.6 running Multi-container Docker 1.7.1 (Generic)
OptionSettings:
  aws:elasticbeanstalk:command:
    BatchSize: '30'
    BatchSizeType: Percentage
  aws:elasticbeanstalk:sns:topics:
    Notification Endpoint: me@example.com
  aws:elb:policies:
    ConnectionDrainingEnabled: true
    ConnectionDrainingTimeout: '20'
  aws:elb:loadbalancer:
    CrossZone: true
  aws:elasticbeanstalk:environment:
    ServiceRole: aws-elasticbeanstalk-service-role
  aws:elasticbeanstalk:application:
    Application Healthcheck URL: /
  aws:elasticbeanstalk:healthreporting:system:
    SystemType: enhanced
  aws:autoscaling:launchconfiguration:
    IamInstanceProfile: aws-elasticbeanstalk-ec2-role
    InstanceType: t2.micro
    EC2KeyName: workstation-uswest2
  aws:autoscaling:updatepolicy:rollingupdate:
    RollingUpdateType: Health
    RollingUpdateEnabled: true
Tags:
  Cost Center: WebApp Dev
CName: front-A08G28LG+
EnvironmentName: front+
EnvironmentLinks:
  "WORKERQUEUE" : "worker+"

Environment Manifest

Extras

  • Platforms not supported in Elastic Beanstalk:
    • Erlang
    • Oracle WebLogic
  • Immutable deployments perform an immutable update to launch a full set of new instances running the new version of the application in a separate Auto Scaling group, alongside the instances running the old version.
    • Immutable deployments can prevent issues caused by partially completed rolling deployments.
    • If the new instances don't pass health checks, Elastic Beanstalk terminates them, leaving the original instances untouched.
  • Dedicated Worker Environment
    • If your application performs operations or workflows that take a long time to complete, you can offload those tasks to a dedicated worker environment. Decoupling your web application front end from a process that performs blocking operations is a common way to ensure that your application stays responsive under load.
  • If your application performs operations or workflows that take a long time to complete, you can offload those tasks to a dedicated worker environment. Decoupling your web application front end from a process that performs blocking operations is a common way to ensure that your application stays responsive under load.
  • Setting up an environment for performing repetitive tasks
    • Setup a worker environment and a cron.yaml file