When you create a load-balanced Elastic Beanstalk environment, what does Beanstalk actually provision in your AWS account, and why is changing those resources by hand a problem?
answer
- a control plane over normal services
- CloudFormation stack owns the resources
- option settings are the source of truth
- hand edits drift and get reverted
- termination deletes what it created
basics
~20 sBeanstalk is a control plane, not a runtime. It drives a CloudFormation stack that creates an Auto Scaling group of EC2 instances, a load balancer, security groups and CloudWatch alarms in your account. Hand-edits are not recorded in the environment configuration and get overwritten.
solid answer
~50 sCreating a load-balanced environment makes Beanstalk build a CloudFormation stack in your account containing a launch template and an Auto Scaling group, EC2 instances booted from the platform AMI with a health agent on them, an Application Load Balancer by default, security groups for the instances and the load balancer, CloudWatch alarms that drive scaling, and an S3 bucket holding your application versions and log bundles. Nothing is hidden: you can see every resource in the EC2 console. The catch is ownership. The environment's *option settings* are the source of truth, so if you resize the Auto Scaling group or edit a listener directly, the change lives outside that record — the next configuration update, deployment or instance replacement can silently revert it, and terminating the environment deletes the resources Beanstalk created. Change things through option settings, `.ebextensions`, or `.platform` hooks instead.
code
yaml · 8 linesoption_settings:
aws:autoscaling:asg:
MinSize: 2
MaxSize: 6
aws:autoscaling:launchconfiguration:
InstanceType: t3.small
aws:elasticbeanstalk:application:environment:
APP_ENV: productiongo deeper
Know that Beanstalk creates ordinary resources — EC2 instances, an Auto Scaling group, a load balancer — in your own account, and that you can see them in the console.
Explain the CloudFormation-stack mechanism and the option-settings contract, and say why editing the Auto Scaling group directly does not survive the next configuration update or deployment.
Demonstrate operational judgment: choose a deployment policy for the risk profile, keep stateful dependencies outside the environment stack, and move on-instance setup into platform hooks so it survives instance replacement.
Own the standardisation question — whether an opinionated stack composed for you is worth giving up direct control of the primitives, and what guardrails prevent teams from accumulating undocumented manual edits.
## Beanstalk is an orchestrator, not a runtime The single most useful fact about Elastic Beanstalk is that it does not run anything itself. It is a control plane that composes ordinary AWS services. When you create an environment, Beanstalk generates a CloudFormation template and creates a stack from it; every resource in your environment is a normal resource that stack owns. This is why "why not just use Beanstalk?" is a fair question with a nuanced answer — you are not buying different compute, you are buying someone else's opinion about how to wire the compute you would have used anyway. ## The inventory For a load-balanced web server environment on a language platform, expect roughly: - a **launch template** and an **Auto Scaling group** with the min/max you configured; - **EC2 instances** booted from the platform AMI, each running the Beanstalk host manager and, with enhanced health reporting enabled, a health agent that reports per-instance metrics and request statistics back to the service; - an **Application Load Balancer** (the default for new environments; Classic and Network load balancers are selectable at creation and cannot be changed afterwards) with a target group and listener; - **security groups** for the instances and the load balancer, wired so only the load balancer reaches the app port; - **CloudWatch alarms** that implement the environment's scaling triggers; - an **S3 bucket** in the account holding application version bundles and requested log bundles; - an environment **CNAME** under `elasticbeanstalk.com`; - for a *worker* environment instead of a load balancer: an **SQS queue** plus the on-instance daemon that reads it and POSTs each message to the application on localhost, and, when periodic tasks are configured, a **DynamoDB table** used for leader election. A single-instance environment swaps the load balancer and Auto Scaling group work for one instance with an Elastic IP — cheaper, and the usual shape for `dev`. ## How configuration is supposed to flow Everything Beanstalk knows about the environment is expressed as **option settings**, which are namespaced key/values. `aws:autoscaling:asg` carries `MinSize`/`MaxSize`; `aws:autoscaling:launchconfiguration` carries `InstanceType` and the key pair; `aws:elasticbeanstalk:application:environment` carries your environment variables. You set them from the console, the EB CLI, a saved configuration, or a `.config` file under `.ebextensions/` in the source bundle: ```yaml option_settings: aws:autoscaling:asg: MinSize: 2 MaxSize: 6 ``` Beanstalk translates those into the CloudFormation stack. That is the whole contract. ## Why manual edits bite Suppose traffic spikes and someone raises the Auto Scaling group's desired capacity in the EC2 console. It works — for a while. But the environment's option settings still say what they said, so the next configuration update regenerates the stack from them, a scaling action driven by the alarms moves capacity anyway, and an immutable deployment replaces the group wholesale. The change evaporates and nobody can explain why. The same applies to editing listener rules, swapping a security group, or attaching a volume by hand. Two harder edges follow. First, **terminating the environment deletes what Beanstalk created**, so a database provisioned *inside* the environment dies with it — which is why production databases are always created outside and attached by environment variable. Second, resources you attach by hand are not deleted on termination and become orphans nobody recognises. ## The supported escape hatches In increasing order of power: option settings for anything Beanstalk models; a `Resources:` block inside an `.ebextensions` `.config` file, which injects raw CloudFormation resources into the environment's own stack so they are created and deleted with it; `files:`, `packages:` and `container_commands:` for on-instance setup; and, on Amazon Linux 2 and 2023 platforms, **platform hooks** — executable scripts under `.platform/hooks/prebuild`, `predeploy` and `postdeploy` in the source bundle, with `.platform/confighooks/` running the equivalent on configuration updates. Hooks are the modern route and are much easier to reason about than `container_commands`. ## Deployments replace or mutate instances The deployment policy decides which. *All at once* is fastest and drops capacity. *Rolling* and *rolling with an additional batch* update instances in batches. *Immutable* launches a full set of new instances in a temporary Auto Scaling group, health-checks them, moves them into the environment's group and terminates the old ones — slow and it needs double capacity, but a failed deployment leaves the original instances untouched. *Traffic splitting* sends a percentage of requests to a temporary set for canary evaluation. Anything you did by hand on the old instances is gone after any of the instance-replacing policies, which is the practical reason the escape hatches live in the source bundle rather than in someone's SSH session.
- Beanstalk offers several deployment policies — what is the practical difference between rolling and immutable?Rolling updates the existing instances in batches: fast, but capacity dips and a bad build lands on live instances, so recovery means deploying again over those batches. Immutable launches a complete new set of instances in a temporary Auto Scaling group, health-checks them, then moves them across and terminates the old ones. It takes longer and needs double capacity briefly, but a failed deployment leaves the running instances untouched.
- What happens to the resources when you terminate a Beanstalk environment?Beanstalk deletes the environment's CloudFormation stack, so everything it created — instances, Auto Scaling group, load balancer, security groups, alarms — is removed. Resources created outside the environment survive, as does the S3 bucket holding application versions. The trap is a database provisioned inside the environment: it is stack-owned and goes with it, which is why production data stores are always created separately and passed in by environment variable.
- On the Amazon Linux 2 and 2023 platforms, how do you run your own code during a deployment?Platform hooks: executable scripts placed under `.platform/hooks/prebuild`, `.platform/hooks/predeploy` and `.platform/hooks/postdeploy` in the source bundle, run in lexical order as root at those points of the deploy. `.platform/confighooks/` runs the same phases on a configuration update. They are the supported successor to `.ebextensions` `container_commands` and are far easier to debug.
saying these in an interview costs you the question
- Thinks Beanstalk runs code on hidden AWS-managed capacity
- Sets ASG desired capacity in the EC2 console and expects it to stick
- Deletes Beanstalk-created security groups as unused
- Believes .ebextensions can only set environment variables
- Provisions the production database inside the environment