Pause an Elastic Beanstalk app environment?

I want to shut down the app servers while I upgrade the database.

Is there a way to pause or stop the app servers without terminating/destroying the environment?

Can I just go to the Elastic Beanstalk load balancer and change that temporarily without any issues or consequences to the Elastic Beanstalk configurations or the way it manages its servers?


Solution 1:

This is the only method that worked for me.

1) Go to the environment you want to pause on AWS Management Console

2) Select "Configuration"

3) Open "Capacity"

4) Scroll all the way down to "Time-based Scaling"

5) Click the "Add schedule action" button

6) Set the action to few minutes in the future (recommended: 5 minutes so environment has time to reset), give it a name (for example "terminate") and set minimum and maximum instances to '0':

New scheduled action

Note that times are set in UTC. You can use time.is/UTC to determine the current UTC.

This would create an error that would shut down your environment so you won't have to pay for it. Any other methods suggested just create a error at time of applying so it doesn't pass through and environment would still work.

To re-enable the environment, just schedule another action with instance min 1 and max 4 for example (those are the defaults).

Solution 2:

From AWS What's New blog Dec 16, 2016:

You can now restore AWS Elastic Beanstalk environments that have been terminated. You can restore Elastic Beanstalk environments within 42 days of their termination, and the restored environments will retain the original environment IDs, CNAMEs, application versions, and configuration options.

You can use the Elastic Beanstalk console, EB CLI, AWS CLI, SDK, and API to restore environments that have been terminated. Visit the documentation to learn more.

Solution 3:

Depending on how you orchestrate your AWS Elastic Beanstalk environment, this can be achieved with the EB Command Line Interface's eb scale command for example:

Scales the environment to always run on a specified number of instances, setting both the minimum and maximum number of instances to the specified number.

  • The underlying Auto Scaling settings are also accessible via the Elastic Beanstalk Console's 'Configuration' section, specifically the 'Scaling' tile.

Alternatively you can always manually scale down the auto scaling group yourself by setting the minimum and desired number of instances to zero.

  • This can be achieved via the AWS Management Console (accessible via the EC2 section, bottom left features a link to Auto Scaling Groups), the AWS Command Line Interface (the autoscaling reference features resp. commands), or also programmatically via the AWS SDKs, in case you want to include it into your deployment automation.

Solution 4:

Setting min and max to 0 under Configuration > Capacity > Auto Scaling Group will shutdown the EC2 instance.

enter image description here

Event entry: There are no instances. Auto Scaling group desired capacity is set to zero.

Solution 5:

I could only make this work using the aws-cli by setting the ASG values directly. Scale up to 1 instance:

aws autoscaling update-auto-scaling-group --auto-scaling-group-name <ASG-Name> 
  --min-size=1 --max-size=1 --region <region>

Then to pause, reduce the min size in the ASG to 0:

aws autoscaling update-auto-scaling-group --auto-scaling-group-name <ASG-Name> 
  --min-size=0 --max-size=1 --region <region>`

Then set the desired capacity to 0 to kill the instance:

aws autoscaling set-desired-capacity --auto-scaling-group-name <ASG-Name>
  --desired-capacity 0 --region <region>