# Elastic Beanstalk

Document |

## Overview

* Simply upload your code -> Beanstalk will do all the rest.
* Underlying is EC2, including AutoScaling group.

### Environment tier

* ***Web server environment***: runs a static website, a web app, or a web API that serves HTTP requests.
* ***Worker environment***: Run a worker application that processes <mark style="background-color:yellow;">long-running workloads</mark> on demand or performs tasks on a schedule.

{% hint style="info" %}
one app per environment. can have multiple environments.
{% endhint %}

## Feature

* Simplest way to deploy & run web app
* Auto scaling, load balancing
* ***Auto health monitoring***: auto collect more than 40 key metrics and attributes to determine the health of your web application in one unified interface.
* Fully managed (patching...)
* Complete resource control

## Deployment Policies

### All at once

Deploy new version to all instances. This is the default deployment option.

<figure><img src="/files/dLuXuy5hfShK5Usjiyt8" alt="" width="563"><figcaption><p>All at once</p></figcaption></figure>

### Rolling

* Updates a few instances at a time (batch), and then moves onto the next batch once the first batch is healthy.&#x20;
* The impact of failed deployment is lower compared to All at once since rollbacks are applied in

  batches as well.

### Rolling with additional batch

Similar to Rolling, but Elastic Beanstalk launches an additional batch of instances to ensure that the full capacity is available to serve traffic during the update process.

* Pros: the application always runs at full capacity.
* Cons: some users may continue to see the old version.

<figure><img src="/files/LuhdeI1N7RrzXQZGy5PP" alt=""><figcaption><p>Roliing with additional batch</p></figcaption></figure>

{% hint style="warning" %}
Make sure that your EC2 limits have enough capacity for the deployment to proceed. For example, say you have a quota of 20 instances per region, and you’re already running 19. If your batch size is 2 instances, Elastic Beanstalk won’t be able to create those extra instances
{% endhint %}

### Immutable

Deploys the new version to a fresh group of instances in a new Auto Scaling group. Once the new instances pass health checks, they are moved to your existing Auto Scaling group, and the old instances are terminated.

* Pros: no downtime
* Cons: costly and subjected to on-demand EC2 limits since capacity is doubled for a brief time. It’s also the slowest deployment method.

<figure><img src="/files/ZbKXiOk5XZ7xmJnJZFWV" alt=""><figcaption><p>Immutable</p></figcaption></figure>

### Traffic splitting (Blue/Green)

Deploy the new version to a fresh group of instances and temporarily split incoming client traffic between the existing application version and the new one.

* Pros:&#x20;
  * Suitable for A/B or canary testing.
  * If the new instances do not pass the health checks or if you decide to cancel the deployment, Elastic Beanstalk will simply reroute the traffic back to the old instances and terminate the new instances.

<figure><img src="/files/2szZlBYZcBqby1RkhwxV" alt=""><figcaption><p>Blue/Green</p></figcaption></figure>

## .ebextensions

* Formatting – Configuration files must conform to YAML or JSON specifications.
* Naming – Configuration files must have the `.config` file extension -> YAML or JSON format but naming is `.config`.

{% hint style="warning" %}
If you use a key (for example, `option_settings`) twice in the same configuration file, one of the sections will be dropped.&#x20;
{% endhint %}

## Pricing

No additional charge for ElasticBeanstalk. You need to pay for S3 (store codes) & EC2.

## Best practices

## Trivia

* Anything in the `.ebextensions` folder will be run as part of your Elastic Beanstalk environment creation.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mamawhocode.gitbook.io/aws/services/compute/elasticbeanstalk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
