71

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?

adelphus
  • 9,318
  • 5
  • 35
  • 46
MonkeyBonkey
  • 40,521
  • 63
  • 217
  • 426
  • 1
    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 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.terminating.html. – jarmod Aug 25 '15 at 18:22
  • @jarmod - I think pausing an environment can now effectively be achieved with [eb scale](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-scale.html), see [my answer](https://stackoverflow.com/a/32215124/45773) for details. – Steffen Opel Aug 25 '15 at 22:33
  • If there's only one instance, wouldn't it be possible to just stop the underlying EC2 instance from the EC2 console? – Adam Parkin Dec 14 '17 at 17:10

4 Answers4

87

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

Jorge Orpinel
  • 4,897
  • 1
  • 16
  • 32
Idan
  • 9,363
  • 8
  • 45
  • 75
  • This doesn't work now. Beanstalk validates the config first and jus sends a service message with the error, without applying the config. – Jorge Orpinel Aug 14 '18 at 18:08
  • @JorgeOrpinel Are you sure you are using scaling environment and not "single-instance"? I'm using this on daily basis (scheduled)... – Idan Aug 15 '18 at 07:21
  • 2
    You're right. My scheduled action was never run because I didn't set the time properly! I didn't consider that you have to use UTC time. https://time.is/UTC is useful for this B) It seems to work after all. – Jorge Orpinel Aug 18 '18 at 06:08
  • 2
    @JorgeOrpinel Glad that it's still valid and thank's for improving the answer. :) – Idan Aug 23 '18 at 11:58
  • 1
    It worked for me but I had to also put the desired capacity to zero. But yeah nice answer – Jack7 Oct 30 '18 at 03:01
  • What if I have some files manually installed on the host? Set the instance 1 will wipe them out I think. – chrisTina Mar 04 '19 at 21:05
  • This will terminate EC2 instances, not the environment itself. You will still pay an hourly rate for your load balancer. – Yan F. May 15 '20 at 21:39
16

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.

Community
  • 1
  • 1
Robert Claypool
  • 4,083
  • 9
  • 47
  • 59
13

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.

Steffen Opel
  • 61,065
  • 11
  • 183
  • 208
  • 6
    hmm it seems like it won't let me set it to 0 – MonkeyBonkey Sep 09 '15 at 15:50
  • 1
    @MonkeyBonkey - Have you set both the minimum and desired number to 0? I specifically tried that because I wasn't 100% positive on the resp. EB behavior either, and there might be some constraints in this regard indeed - however, it worked fine for me, the environment has simply been marked as red aka unhealthy thereafter, but other than that it just worked and stayed like that until I terminated it a few hours later. – Steffen Opel Sep 09 '15 at 16:34
  • yeah I tried that and it said that max can't be smaller then min and won't let me set 0 on either. – MonkeyBonkey Sep 09 '15 at 16:56
  • 1
    That's odd, what solution stack are you using? Either way, an alternative might be to go to the Auto Scaling Group management in the EC2 Console (bottom left from the dashboard) and adjust the resp. ASG from there - this is not under control of Elastic Beanstalk, thus _might_ circumvent any EB specific constraints. – Steffen Opel Sep 09 '15 at 17:53
  • @SteffenOpel scale works if it is a load-balanced server. If not, you would get this message: `The environment is currently a single-instance. Do you want to change to a load-balancing environment? WARNING: If you choose yes, the environment and your application will be temporarily unavailable.` – Jun711 Oct 01 '18 at 17:50
1

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.

timomeinen
  • 2,630
  • 3
  • 27
  • 41