AWS can get very expensive as your company grows and you start using more of it’s features. There are however few easy ways to save money with AWS and make the most of cloud computing.
1. Use correct instance type
In cloud it’s easy to resize instances as you need to always start small, and expand as you need it. Think about how your server will be used. Does it need to be up all day and will it receive steady flow of traffic? For servers that might experience high levels of traffic during office hours, i.e. admin panels, report tools, etc – look into burstable t2 instance family. They collect CPU credits in quiet times (i.e. during night) and are then able to release them when needed. Please note, there is a different max CPU credits cap per each instance size, and it lasts for 24 hours, so you can’t roll them over. t2 instances are also really good for test and developer environments.
|Instance type||Instance name||Best use|
|Burstable Instances||t2||Instances that don’t use full CPU often, staging and developer environments|
|General Use||m3, m4||Caching servers, cluster computing|
|Compute Optimized||c4, c3||Web Servers, Science and Engineering applications, video-encoding|
|Memory Optimized||x1||in-memory databases|
|r3||high performance databases|
|GPU||g2||3d application streaming, machine learning, video encoding|
|High I/O||i2||NoSQL databases, data warehousing that requires quick SSD write, cluster drive systems|
|Dense-storage||d2||Instances that require up to 48TB of storage, MPP, data warehousing, MapReduce and Hadoop|
2. Switch off staging environments at night
Unless you run teams across different time-zones you can save up to 2/3rd of your daily spend on staging environments by switching them off out of hours. I usually tend to keep the database running on week days, with it being destroyed on Friday and re-created on Monday because our databases are so big, and they take a while to purge unnecessary data for the staging environments. Every night the ElastiCache servers get nuked totally, and then recreated in the morning, empty, as they only hold the cache, which will then get populated, as QA starts testing in the morning. This process is pretty quick, and if you want to see the ansible code that stops and starts the server, check it on my github here: https://github.com/kgogolek/aws-switch-off-environment
3. Reserved Instances
If you know what servers you run day-to-day and if you can predict that you might be running X number of web servers on daily basis for the next year or so, then it’s worth looking into Amazon EC2 Reserved Instances. You can purchase them up-front for 1-3 years in exchange for a significant discount (amazon claims that to be up to 75%). This is an easy way of saving when you run an established site, and can predict your workloads. The service is quite flexible in payment as you can pay it all, pay part of the fee or pay nothing upfront, but please note that the more you pay up front, the more you will save. You can also always modify or sell your reserved instances if your needs change.
4. Spot Instances
On the other hand, you might be running servers that are easily disposable, and can do the job at any time, as long as they do the job. To get spot instances, you choose the price you are willing to pay per instance hour, by putting a bid in your request. When your bid meets or exceeds the current spot price your request will be started up, and run until you decide to terminate them, or the spot price will increase above the threshold you specified. This is great for non-time specific computations, and servers that don’t need to be up all the time.
5. Make the most of Lambda
If possible investigate if that script that resizes lots of images, or creates reports from your database can be moved into Lambda. Lambda supports micro services written in Java, python and node, and can be used with an AWS API Endpoint if you need a remote trigger from your application. The scripts are easy to write and to maintain, and you don’t have to worry about scaling. You pay just for the processing time, and at the time of writing Lambda supports jobs that need to run up to 5 minutes long, so this should cater to most of your needs. Or maybe even consider running server-less instead of having webservers up all day, every day.
6. Follow Trusted Advisor’s guidance
AWS provides you with Trusted Advisor, a list of suggested improvements in 4 categories: Cost Optimization, Performance, Security and Fault Tolerance. Here you will see the list of potential improvements that can be done. Have you got any idle load balancers you forgot about? You pay $20 a month for each of them whether they run or not, so remove them if they’re not needed. Have you got any under-utilised EC2 Instances – you can get a quick glance at what the usual CPU is and scale the instance type down if you can to make sure you’re not wasting money on servers that are not even doing much. This will also help you spot the most expensive servers. Maybe some code optimisation or a cache layer could lower the load on those?
7. Release your EIP’s
You pay for Elastic IPs when they are not attached to an instance, so make sure you delete them, when you terminate the EC2 instances attached to them.
I hope you find this article useful and manage to save money with AWS. If there is anything else you use, let me know. Cloud computing gives you so many brilliant tools to manage the infrastructure, but it’s easy for the cost to escalate, as you push for new features.