Deploying Android Emulators on AWS EC2 [3/3] | Autoscaling Bare Metal Instances| Cost Optimizations for Organization

Uddeshya Singh
Feb 18 · 4 min read
Photo by Paul Hanaoka on Unsplash

To condense this entire post into one sentence: It would be you can host a well-running android emulator on the AWS cloud for about $0.0325 per hour.

Got your attention? Good.
Welcome to the final post of a 3 part series Deploying Android Emulators on AWS EC2. In this post, I would like to introduce you to the wonders of spot instances and how can you exploit their cheapness to your own benefit. But before we dig into that, in case you somehow directly jumped to this post, I'd suggest you check out the last 2 ones too to get a recap of what we’ve been up to till now.

So, what are Spot instances? 💳

Taking the definition off the AWS website “A Spot Instance is an unused EC2 instance that is available for less than the On-Demand price. Because Spot Instances enable you to request unused EC2 instances at steep discounts, you can lower your Amazon EC2 costs significantly. The hourly price for a Spot Instance is called a Spot price.”

Note, Spot instances are excellent for the use cases where you can afford your applications to be interrupted, or you have backup instances to complete unfinished jobs those applications hosted on that particular instance were supposed to handle. In addition to those, there are certain things I would recommend you to go through before considering Spot instances as your option:

  • The hourly price of a Spot instance varies while that of the On-demand instance is static.
  • If capacity is not available, the Spot Request continues to automatically make the launch request until capacity becomes available. This means it doesn’t guarantee that your instances are always up. i.e. there is always a possibility (however minuscule it might be) that your emulators are never up and running

Alright, now that we are done with the disclaimers, allow me to show you the price reduction chart, the entire reason why you are reading this post

As you can see there is about ~90% cost reduction in on-demand to spot instances. This, my dear friend, is

Why Autoscaling Groups? 🧑‍🏫

Looking over disclaimers, you would notice instance interruption. No, the question can be asked, what if I create a simple spot instance and it gets interrupted, will I get it back? No. You won’t.
So do you need to keep creating and configuring EC2 machines again and again? No, you don’t need to do that either.

This is where autoscaling groups come in handy. The ASG requires a Launch Template, which is essentially an image of the instance you have pre-configured to run on multiple new EC2 instances.

What does a launch config look like? 👀

Here you can see that sampleEmulatorTemplate specifies a specific instance type (m5.metal) and the AMI ID (the instance image to be deployed in auto scaler groups). You can specify key-pair logins, security groups, etc in this too.

Autoscaler Magic ✨

Now, for the money shot, you can deploy your EC2 instance image on a “desired” number of new machines. Using the following settings:

Here you can see three settings in your auto scalers tab, Desired capacity is the number of instances we want at all the time. Minimum Capacity is the minimum number of instances that should always be there regardless of the cost incurred. Maximum Capacity is the maximum number of instances you would want to spawn in the group.

The next important question to address is usually how to ensure that your scaler uses the spot instances only, for that you can make sure your instance purchase configurations look like this

  1. We are not adhering to the launch template because we want spot instances here, regardless of the type of instances our launch template is using (ex: on-demand / reserved)
  2. You always want 100% spot instances. NO MATTER WHAT.
  3. Don’t tick capacity rebalance, to gracefully shutdown your spot instances, it might replace them with on-demand instances to ensure a smooth transition.

Conclusion 🎩

This brings us to the conclusion of our cost optimization attempts. You can play around with your instance types and see what alternatives you can use, for example, m5.metal can be replaced with m5d.metal as per your needs and it might run just fine according to the instance demands. Rest assured, you can use the same configs shared here in other ASG deployments and it would optimize the costs in a similar basis.

Resources 🔗

The Startup

Get smarter at building your thing. Join The Startup’s +794K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +794K followers.

Uddeshya Singh

Written by

Google Summer of Code ’19 @fossasia | @tensorflow, @fossasia Mentor — Google Code In ’19 | Full Stack Developer by Profession, Writer and Reader by hobby

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +794K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store