Pause an Elastic Beanstalk app environment?

Amazon Web-ServicesAmazon Elastic-Beanstalk

Amazon Web-Services Problem Overview


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?

Amazon Web-Services Solutions


Solution 1 - Amazon Web-Services

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 - Amazon Web-Services

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 - Amazon Web-Services

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.

Solution 4 - Amazon Web-Services

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 - Amazon Web-Services

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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMonkeyBonkeyView Question on Stackoverflow
Solution 1 - Amazon Web-ServicesIdanView Answer on Stackoverflow
Solution 2 - Amazon Web-ServicesRobert ClaypoolView Answer on Stackoverflow
Solution 3 - Amazon Web-ServicesSteffen OpelView Answer on Stackoverflow
Solution 4 - Amazon Web-ServicestimomeinenView Answer on Stackoverflow
Solution 5 - Amazon Web-ServicesbwobbonesView Answer on Stackoverflow