One of the benefits of using a cloud provider like AWS is the ease of spinning up resources such as a new EC2 instance or storing more data in S3. As developers, we are generally more focused on getting our product or feature to the users as quickly as possible. However, we generally don’t think about costs until we see the bill at the end of the month and are left wondering how we ended up spending so much money.

In this article, we will look at the different ways available to monitor and reduce your bill significantly.

Monitoring

Extensive monitoring is essential for reducing your costs and keeping them low in the future. Amazon provides a few tools to track your costs easily and accurately:

  • Cost Explorer: This is a tool which lets you view your costs easily. The tool shows historical data so that you can see how your cost is changing over time. The cost explorer also lets you filter based on a bunch of criteria such as the service, the region etc. More information about how to use the Cost Explorer is available here.

  • Use Tags everywhere: A tag is a label that can be assigned to any AWS resource. Tags can be used to organize your resources and can help in tracking costs in more detail. For example, if you wanted to know the cost of a particular feature or service, you could add tags to all the resources being used by that service and the cost report will be able to show you the cost for that service. More information about how to use tags for tracking cost is available here.

  • Create billing alerts: An important component of any good monitoring system is being able to alert based on certain conditions. AWS lets you create billing alerts that send notifications when the usage exceeds the defined thresholds. More information about how to create alerts is available here.


Once you start monitoring your costs, you should have a much better idea about which services and resources are the most expensive and what you want to optimize.

Let’s look at how to reduce the cost for some of the more popular AWS services.

AWS EC2

EC2 is generally the biggest cost driver for most people. Amazon charges for On-Demand EC2 instances based on the amount of time the instances run for.

Different techniques that can be used to significantly reduce EC2 costs are:

  • Use Reserved instances: Reserved Instances (RI) can provide a significant discount (up to 75%) compared to On-Demand instances. Purchasing reserved instance is an easy way to reduce your cost significantly. However, you should only purchase a Reserved Instance if you are sure that you will be needing the resources for long-term use.

    Amazon provides a couple of different types of Reserved Instances:

    • Standard RI: These provide the most significant discount (up to 75%) and are best when you know which instance type and region for your service and are willing to commit to it.
    • Convertible RIs: These are a bit more expensive than the Standard RI but they provide a lot of flexibility to change the attributes of the RI.

    More information about Reserved Instances is available here.

  • Use Spot instances: Amazon provides any spare capacity at heavily discounted prices as compared to On-Demand instances. These instances are referred to as Spot Instances. A major difference between On-Demand instances and Spot instances is that Spot instances can be interrupted whenever Amazon needs the capacity back.

    Spot instances are perfect for services where you can tolerate a temporary loss in service availability in return for much lower costs. Some examples of such services could be your test infrastructure or your asynchronous task processing service.

    You can learn more about how spot instances work by going to this link.

  • Use AutoScaling: AutoScaling allows you to dynamically scale your EC2 capacity based on predefined conditions. Without AutoScaling, capacity has to be provisioned based on the peak load. However, that leads to underutilized resources whenever the load is much lower. This is especially true if you have a service where the load pattern is cyclical. With AutoScaling, you no longer have to worry about idle capacity. Your capacity changes depending on the load on the system. This can lead to a significant reduction in cost.

  • Choose the correct instance type: Choosing the appropriate instance type for your application is very important. You should spend time understanding and benchmarking your application to understand the requirements for the application. Amazon offers different instance types based on different use cases such as compute, memory, general purpose.

    Learn more about the different instance types available here.

  • Be aware of Data transfer costs: Amazon charges data transfer costs for moving data out of EC2. These costs can be pretty high if you continuously move data between different AWS region. Try to avoid having services in different regions which need to communicate with each other.


AWS S3

Amazon Simple Storage Service (Amazon S3) is one of the most popular AWS services. It is very easy to use and it can become pretty expensive over time as the amount of data being stored on S3 can grow pretty quickly.

S3 charges based on the amount of data stored as well as how frequently that data is accessed.

  • Learn about the different S3 storage classes

    S3 has three storage classes:

    • Standard: This is the default storage class for all data stored in S3. This storage class provides the highest availability compared to the other storage classes. This is also the most expensive storage class.
    • Infrequent Access (IA): This storage class is ideal for data that is less frequently used than Standard but provides the same latency and throughput. However, this storage class is significantly (almost 50%) cheaper than standard storage.
    • Glacier (Archive): Glacier is ideal for data archiving. Glacier provides a very cheap solution for data which needs to be stored for a long time and only needs to be accessed rarely.


  • Use Amazon S3 Analytics: Amazon provides this tool to analyze the data in your S3 buckets. You should use this data to make decisions about which storage class is most appropriate for your data. More information about how to use this tool is available here.

  • Use Lifecycle policies aggressively: Amazon lets you set policies about when to transition objects in S3 from one storage class to another automatically. It also lets you set expiration policies which can be used to automatically delete any data after a certain time. These policies should be aggressively for any data that is temporary to make sure that S3 costs don’t keep increasing over time. More information about lifecycle policies is available here.

  • Compress your data before storing in S3: Always compress your data before storing it in S3. This helps in significantly reducing the amount of data being stored in S3. Big data applications generally store a lot of data in S3 and if the data is not compressed in the right format this can cause S3 costs to grow very fast.


Conclusion

Amazon provides a lot of tools to be able to monitor and track your costs. Once you start monitoring your costs, it can be much easier to reduce your costs. I hope this tutorial will be helpful to you and you can apply some of these tips in trying to reduce your own AWS bill.

Please feel free to leave any comments below if you have any questions or feedback.