How to Pause AWS Elastic Beanstalk Environments Without Termination for Cost Optimization


3 views

Many developers working with AWS Elastic Beanstalk face this common scenario: You need to temporarily pause your environment for testing or development purposes, but don't want to completely terminate it and lose your configuration. Unfortunately, Elastic Beanstalk doesn't provide a direct "Stop" button in the management console like EC2 instances do.

The most effective solution is to scale your environment down to zero instances. This achieves the same result as stopping - no resources are running so you won't incur compute charges, while maintaining all your environment configurations.

Here's how to do it programmatically using AWS CLI:


# Scale down the environment
aws elasticbeanstalk update-environment \
    --environment-name your-env-name \
    --option-settings Namespace=aws:autoscaling:asg,OptionName=MinSize,Value=0 \
                     Namespace=aws:autoscaling:asg,OptionName=MaxSize,Value=0

For teams that frequently need to pause environments, creating a script can save time. Here's a more complete example with error handling:


#!/bin/bash

ENV_NAME="your-environment-name"
REGION="us-west-2"

# Verify environment exists
if ! aws elasticbeanstalk describe-environments --environment-names $ENV_NAME --region $REGION | grep -q "EnvironmentName"; then
    echo "Environment $ENV_NAME not found"
    exit 1
fi

# Scale down
aws elasticbeanstalk update-environment \
    --environment-name $ENV_NAME \
    --region $REGION \
    --option-settings \
        Namespace=aws:autoscaling:asg,OptionName=MinSize,Value=0 \
        Namespace=aws:autoscaling:asg,OptionName=MaxSize,Value=0

if [ $? -eq 0 ]; then
    echo "Successfully scaled down environment $ENV_NAME"
else
    echo "Failed to scale down environment"
    exit 1
fi

While this approach stops the compute charges, be aware that:

  • You'll still incur charges for any attached storage (like RDS or EBS volumes)
  • Environment health will show as "Severe" when scaled to zero
  • DNS records remain active but won't route to any instances

When you're ready to resume work, scale back up to your desired instance count:


aws elasticbeanstalk update-environment \
    --environment-name your-env-name \
    --option-settings Namespace=aws:autoscaling:asg,OptionName=MinSize,Value=1 \
                     Namespace=aws:autoscaling:asg,OptionName=MaxSize,Value=1

For more complex environments, consider using saved configurations:


# First save your current configuration
aws elasticbeanstalk create-configuration-template \
    --application-name your-app-name \
    --template-name paused-config \
    --environment-name your-env-name

# Then terminate the environment when needed
aws elasticbeanstalk terminate-environment \
    --environment-name your-env-name

# Later recreate using saved config
aws elasticbeanstalk create-environment \
    --application-name your-app-name \
    --environment-name new-env-name \
    --template-name paused-config

Many developers face this frustrating scenario: You need to temporarily stop your AWS Elastic Beanstalk environment for testing or development pauses, but the platform only offers termination as the primary "stop" mechanism. Unlike EC2 instances which can be stopped/started, EB environments are designed for continuous operation.

Terminating your environment means:

  • Losing all environment configurations
  • Requiring full redeployment when restarting
  • Potential DNS changes affecting integrations
  • Losing historical metrics and logs

Here are three proven methods to effectively pause your EB environment:

1. Scaling to Zero

The most straightforward approach is to scale your environment to zero instances:

aws elasticbeanstalk update-environment \
    --environment-name YourEnvName \
    --option-settings Namespace=aws:autoscaling:asg,OptionName=MinSize,Value=0 \
                     Namespace=aws:autoscaling:asg,OptionName=MaxSize,Value=0

This maintains all configurations while stopping all EC2 instances. When ready to resume:

aws elasticbeanstalk update-environment \
    --environment-name YourEnvName \
    --option-settings Namespace=aws:autoscaling:asg,OptionName=MinSize,Value=1 \
                     Namespace=aws:autoscaling:asg,OptionName=MaxSize,Value=4

2. Environment Swapping

Create a minimal "placeholder" environment and swap URLs when needed:

# Create placeholder environment
eb create placeholder-env --single --timeout 20

# Swap when pausing main environment
eb swap-env-names --environment-name1 main-env --environment-name2 placeholder-env

3. Scheduled Scaling

For predictable usage patterns, implement scheduled scaling:

aws autoscaling put-scheduled-update-group-action \
    --auto-scaling-group-name Your-ASG-Name \
    --scheduled-action-name "PauseEnvironment" \
    --start-time "2023-12-01T00:00:00Z" \
    --desired-capacity 0 \
    --min-size 0 \
    --max-size 0
  • Database connections may time out during pauses
  • SQS queues will continue accumulating messages
  • Environment health will show "Severe" during pause (normal behavior)
  • Some AWS resources still incur minimal costs (EBS volumes, etc.)

Even when scaled to zero, monitor these aspects:

aws cloudwatch get-metric-statistics \
    --namespace AWS/ElasticBeanstalk \
    --metric-name EnvironmentHealth \
    --dimensions Name=EnvironmentName,Value=YourEnvName \
    --start-time $(date -d '1 hour ago' +%FT%TZ) \
    --end-time $(date +%FT%TZ) \
    --period 3600 \
    --statistics Average