QubOps

Day 16 - Switching off Staging and Test environments

AWS Cost Optimisation Advent Calendar 2024

4 min read time

#aws

Welcome to day 16 of the unofficial AWS Cost Optimisation Advent Calendar 2024, where every day we will be sharing new tips or tricks to help you optimise your cloud costs before Christmas 2024.

Today's tip is about switching off idle resources like your Staging and Test environments when they aren't being used - perhaps over Christmas!

This is one that seems fairly obvious, but in practice is quite challenging to do effectively as there are a number of considerations.

In a nutshell, the goal is that you only pay for resources when you are using them. For example, if your developers and testers aren't working in the evenings, weekends or over Christmas then you are paying for nothing by keeping your Staging and Development environments up.

How to do it

There are a number of ways to achieve this, but here are a few common ones:

  1. Scheduled Events: Use AWS Lambda to schedule events to start and stop your instances at certain times.
  2. Auto Scaling: Use Auto Scaling to scale your instances to zero when they aren't being used.
  3. Instance Scheduler: Use the AWS Instance Scheduler to schedule your instances to start and stop at certain times.
  4. Start and Stop Scripts in CI/CD: Have a start job in your CI/CD system that start your instances when you deploy your application or on a schedule and a stop job that stops them on a defined schedule.
  5. Use a Third Party Tool: We are able to set you up with a simple web interface that allows you to select the resources you want to stop and start and the times. Please contact us if you want us to help you set this up.

Challenges

On the surface this seems like a simple task, but if this practice is not taken into account during the development process it can cause some difficult to debug problems in these environments.

One common example of this is when your application has a task which runs every night on a queue or cron. If the application is shut down during this time this no longer runs and has knock on effects for testers and developers as the staging application will be in an inconsistent state.

Another challenge is getting everything to start up again if testing is needed overnight or over the weekend and the relevant staff aren't around to start it up again which can cause delays in testing.

These and other challenges are the reasons many organisations simply pay for the non-use to avoid the headaches. This is a costly decision that compounds over years and can be avoided with a bit of planning and process.

Overcoming the challenges

If the schedule for your Staging and Test environments is clearly communicated throughout your organisation and the process is well documented, then developers can take this into account as they develop.

For example when setting the schedules for timed jobs they can set a different schedule for the staging or test environments.

If your application depends on tasks running at specific times of day tasks then the environment can be spun up temporarily during those times and shut down again afterwards which can still generate significant savings.

It is important to give your teams a way of preventing the shutdowns or spinning up the environments when they need them.

A common way to do this is to have your start and stop scripts behind an HTTP interface via Lambda or API Gateway so that it can be easily integrated into various tools.

One such tool which is useful is Slack which has a surprisingly simple way of creating a little app which can create commands or buttons in a Slack Channel which hits the endpoints.

With HTTP endpoints you can also make a simple website with start and stop buttons for non-technical staff to use.

Conclusion

Switching off idle resources can be one of the most significant cost saving tools in your arsenal if done correctly.

It can be a bit challenging to implement at first but when it is singing and dancing it will be very satisfying sitting over Christmas knowing you aren't paying for anything you aren't using.

We have implemented this for a number of companies with very simple ways such as an internal webpage to turn environments on and off.

Please reach out if you want us to do the same for your team.

To be the first to know when the next edition is published, follow us on LinkedIn, X, BlueSky or subscribe to the RSS feed.

Join our newsletter for Cost Optimization tips and tricks

By subscribing you agree to our Privacy Policy and provide consent to receive updates from our company.