Back
Guide
13 Feb 2024

How to reduce your AWS bill in 2024 - Includes Bonus Code

How to reduce your AWS bill in 2024 - Includes Bonus Code

AWS is the market leader when it comes to server infrastructure. It provides several services that spans different categories. In this article we will only look into popular AWS services used by SaaS apps on how to reduce their bill. If not optimized properly, AWS bill can easily become a burden for your business especially when you experience user or usage growth.


We will go through different ways on how you can save or reduce your AWS bill in no particular order.


Activate Alerts with AWS Budgets

This is not exactly a saving tip, but to ensure a system is in place for your usage in AWS so that you get pre-emptive alerts whenever you hit a particular AWS bill amount for the ongoing month. This is a must have step unless you don't want any bill surprises at the end of the month. You can set alerts for current costs and also for forecasted costs. When you reach the set limit, an email or sms is sent as a notification. You can set multiple level alerts for different limits as your bill climbs up.


This is very important, as certain services in AWS can suddenly cause a massive jump in costs and go un-noticed until you receive your invoice. This happened for us with CloudFront invalidations which we did whenever a user deleted an object in S3. So play with the budget tool and keep checks in place.


Screenshot 2024-02-13 at 9.55.02 PM.png



Enroll in AWS Startup program

If you are a new business (less than 10 years old) and going to start deploying your application with AWS, then we recommend you to enroll in AWS startup program to save from $1000 to $100000 USD. Activation is usually done in days and credits are applied immediately.


Although it is beneficial only to a certain period i.e. until you exhaust the credits, it is still worth it due to smooth worry-free approval process by the AWS team.


Use Savings Plans instead of Reserved Instances (RI)

EC2 is the base of any SaaS app hosted in AWS. EC2 in other words are cloud servers hosted in AWS infrastructure. It provides tons of flexibility in terms of OS, compute models, configurations. Choosing the right-sized EC2 servers itself is an important step as it should not be under-performing or over-performing for your application needs. To determine this use AWS Compute Optimizer and AWS CloudWatch to analyze your EC2 usage. Over time you can determine the right EC2 instance size for your application.


Apart from choosing the right instances, use the "Savings Plans" option in the same EC2 dashboard to estimate and create an optimized savings plan based on your AWS usage. Savings plan is more flexible than Reserved Instances. Anytime you can change the size of the of your server configuration or also upgrade your instance. The saving plan will still apply and reduce your bill. Whereas with RI you cannot change the EC2 instance size later.


Efficient use of Savings Plan will help you reduce your EC2 costs by about 50%.


Ways to Reduce DB costs in AWS

There are many types of DB, in this article we will only cover RDS the most widely used DB service in AWS. RDS is great as it provides fault-tolerant, automatic backups, easy instance modifications and it is also secure. Just like EC2 choose the right DB instance for your RDS. Do not purchase an RI right away, check the performance and dabble with instance size for atleast a couple of months. Once you are satisfied with its performance, then purchase a long-term RI for the instance. A three-year RI has the best saving in this case.


Reduce file storage costs - AWS S3

S3 provides cloud storage for hosting files in AWS. It is cheaper, secure and provides lots of API based functions that makes it also powerful. While starting out your S3 bill will be on the lower scale as you pay only for the objects stored and bandwidth to access it unlike EC2 or RDS where you pay by the hour. However as your product gets popular and more users store content, your S3 costs will steadily climb up and become a significant part of the bill. There are no savings plan this time to save it. But there are other things that can be done.


Monitor S3 storage by user. And couple it with their user activity. If the user is dormant than it is advisable to write a script to archive their assets to AWS Glacier, this will reduce storage costs by over 50% for that user.


Enforce lifecycle management in S3 settings to remove temporary files like exported data which are usually not required after the user has downloaded it.


NodeJS Code to calculate folder size in S3 (requires AWS SDK3)

async calculateUserFolderSize( folderName) {
let totalSize = 0;
const params = {
Bucket: AWS_BUCKET,
Prefix: folderName
};
const listObjects = async (token) => {
try {
const command = new aws.ListObjectsV2Command({
...params,
ContinuationToken: token,
});
const data = await aws.s3.send(command);
// Sum up the size of each object in the folder
data.Contents.forEach((obj) => {
totalSize += obj.Size;
});
// If there are more objects, recursively call listObjects again
if (data.IsTruncated) {
await listObjects(data.NextContinuationToken);
} else {
return totalSize;
}
} catch (error) {
throw error;
}
};
return listObjects();
}


Reduce AWS CloudFront costs

If you are using S3 or EC2, then you might be using CloudFront as a CDN frontend for these services. CloudFront definitely improves your application and file access performance by reducing TTTB and caching content at edge locations closer to your user.


Also CloudFront is the only easy way with which you can access your S3 objects with custom domain using SSL. Like any other CDN service, CloudFront is an expensive service and should be used with caution especially if budget is a constraint. There are

other less expensive ways to speedup app performance like using AWS Global Accelerator and Reverse Proxy.


Other ways to do reduce CloudFront costs is by doing consolidated invalidations instead of per object invalidation. Increase caching period of CloudFront objects.


Setup AWS WAF, firewall

Using WAF does not directly reduce any costs but prevents unintended costs from bots, spam and cyber attacks. It is important to have these systems in place as guardrails for any unintended usage of resources.


Offload from AWS

Not everything has to be hosted by yourself. For example to host a blog, helpcenter, will add upto your AWS server costs, backup charges and maintenance hours. It is better to offload such tasks to reliable third-party services such as WordPress, WebFlow, SubPage.



Conclusion

Overall hosting in AWS will be actually a costly affair than hosting in a bare-metal service. But then AWS offers robust infrastructure, tons of options, numerous services and powerful APIs. Investing in AWS should also include proper budgeting and taking appropriate saving measures like mentioned in this article for better business outcomes.





Share:

Stay Updated with Our Latest Blog Posts

Subscribe to receive the latest insights, articles, and updates straight to your inbox.

...