73
votes

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?

5
It used to support CLI commands 'eb stop' and 'eb start' but no longer does. Suspect you need to take snapshots of data, then terminate and re-create the environment from the same version. See docs.aws.amazon.com/elasticbeanstalk/latest/dg/….jarmod
@jarmod - I think pausing an environment can now effectively be achieved with eb scale, see my answer for details.Steffen Opel
If there's only one instance, wouldn't it be possible to just stop the underlying EC2 instance from the EC2 console?Adam Parkin

5 Answers

90
votes

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).

17
votes

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.

13
votes

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.

2
votes

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.

0
votes

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>