Sitemap
Platform Engineer

Solving unanswered questions in high-scale web applications

Saving Big on AWS: Best Practices for Cost Optimization and Efficiency

8 min readMar 16, 2023

--

Looking to optimize your AWS costs? In this blog, we’ll share the best practices for AWS cost optimization, including tips and strategies for achieving optimal cost savings and improving your efficiency. Whether you’re a new AWS user or an experienced one, these insights will help you reduce your cloud expenses while leveraging the best features on the cloud.

Use AWS EC2 On-Demand, Reserved, or Spot instances

Instead of always relying on Dedicated instances, try these cost-effective options as well. On-demand instances provide flexibility and no upfront costs, spot instances offer potential cost savings for non-critical workloads, and reserved instances are ideal for applications with predictable or steady-state workloads.

AWS EC2 On-Demand vs Reserved vs Spot instances (Image: Slideshare.net)
  • On-Demand Instances: On-demand instances provide compute capacity on an hourly or per-second basis, with no upfront payment or long-term commitment required.
    Benefits: Easy to use and flexible, with no upfront cost and no long-term commitment.
    Use cases: Ideal for workloads with short-term, unpredictable, or variable usage patterns.
  • Spot Instances: Spot instances allow you to bid on unused EC2 capacity, and provide the potential for significant cost savings (up to 90%) compared to on-demand instances.
    Benefits: Cost-effective for applications that can tolerate interruptions and can be run at any time.
    Use cases: Ideal for non-critical workloads, batch jobs, or tasks that can be stopped and started without affecting user experience or application performance.
  • Reserved Instances: Reserved instances are purchased for a one- or three-year term, with a discounted hourly rate compared to on-demand instances.
    Benefits: Cost-effective for applications with predictable or steady-state workloads, and provide capacity reservation.
    Use cases: Ideal for applications with consistent, long-term usage patterns, such as production environments or applications with steady-state workloads.

Right-size your instances

When selecting a service, whether it’s EC2 or a managed service like RDS, ensure that you’re using instances that are appropriately sized for your workload. Avoid using instances that are over-provisioned and consuming unnecessary resources, which can increase costs.

EC2 comes in a variety of instance types specialised for different roles. Pick the right one with optimum resource configurations (Image: Helenanderson.co.nz)

Use CloudFront for content delivery

Amazon CloudFront is a content delivery network that can help improve the performance of your website or application by caching content at edge locations around the world. This can reduce the number of requests to your origin server (or service) and save on bandwidth costs.

AWS CloudFront retrieves data stored in the Amazon S3 bucket and distributes it to numerous edge locations across the world (Image: Intellipaat.com)

Use AWS Auto Scaling

AWS Auto Scaling allows you to automatically adjust the number of EC2 instances based on traffic or other metrics. This can help ensure that you have the right amount of capacity at all times, while avoiding overprovisioning and unnecessary costs.

With AWS Auto Scaling, minimum and maximum instance settings ensure your EC2 count stays within size limits. You can set a desired capacity and scaling policies for launching or terminating instances based on application demand. (Image: docs.aws.amazon.com)

✅ Configure scheduled shutdowns for non-production resources during off-peak hours

Many expensive AWS-managed services (e.g. EKS Clusters, DocumentDB, RDS, EC2) allow shutting them down to save certain costs, especially related to computing and networking (however, they still charge for storage). Since these resources may not be fully utilized during off-peak hours, especially when they belong to non-production, you can set up planned shutdowns or some scaling-down mechanism to save costs.

This solution leverages AWS Lambda functions to start and stop instances. These functions are triggered by Amazon EventBridge rules using a cron expression to check if any RDS/EKS resource is configured with predefined tags and ready to start or stop. You can check the progress on each Lambda trigger using CloudWatch Logs. Source: Yahia Ghosheh

✅ Upgrade versions on time to avoid higher extended support costs

According to recent announcements, AWS is planning to charge higher prices for providing extended support to workloads using older versions on certain expensive services like EKS and RDS (this trend is likely to escalate to other services in the future).

For extended support for older Kubernetes versions on EKS, the pricing would be almost 6x times. Source: aws.amazon.com/blogs

On EKS, starting April 1, 2024, you will be charged a total of $0.60 per cluster per hour, not the usual $0.10 (400$+ per month).

On RDS, it’s $0.112 in Ireland per vCPU per hour — so, for small, 2-CPU database instances, it will be an additional $ 163.52 per month.

It is clear that keeping up with each technology project’s release calendar, while applying all security patches and necessary updates, is practically difficult for AWS — and they may probably use higher pricing here. Anyway, for an end user, this is an additional cost — therefore, it is highly recommended to keep all the technology versions up-to-date and avoid such unnecessary costs when using AWS services.

Use AWS Trusted Advisor

AWS Trusted Advisor is a tool that provides recommendations for optimizing your AWS infrastructure, including cost savings. Trusted Advisor can help identify underutilized resources, provide optimization recommendations, and monitor your infrastructure for security and compliance issues.

How AWS Trusted Advisor helps organizations optimize their cloud infrastructure (Image: aws.amazon.com)

Use storage classes

AWS offers multiple storage classes, each with different costs and performance characteristics. Use the appropriate storage class for your workload to optimize costs.

Using AWS storage classes can help reduce costs by providing tiered pricing, lifecycle policies, reduced redundancy options, optimized performance, and integrated services, enabling you to choose the most appropriate storage option for your data and optimize your storage costs. (Image: dev.to)

Use Amazon S3 lifecycle policies

Amazon S3 lifecycle policies allow you to automatically transition objects to lower-cost storage classes or delete them when they are no longer needed. This can help reduce storage costs over time.

Amazon S3 lifecycle policies allow to transit of objects from one storage class to another storage class and also over time, delete expired objects automatically on your behalf. (Image: cloudiofy.com)

Use AWS Lambda

AWS Lambda allows you to run code without provisioning or managing servers. If your workload has a low frequency of requests and doesn’t require a lot of computing power, AWS Lambda can be cheaper because you only pay for the actual compute time used by your code, and not for idle time.

If your workload is small and sporadic, AWS Lambda will be the cheaper option (Image: simform.com)

Use managed services

AWS offers a variety of managed services that can help you reduce costs by offloading the management of infrastructure and reducing the time and effort required to manage your workloads. For an instance, instead of running your own PostgreSQL/MongoDB database instance on EC2 or EKS (Kubernetes) Cluster, it would be much more convenient and cost-effective to use AWS RDS/DocumentDB.

AWS Managed Services (AMS) provides full-lifecycle services to provision, run, and support your infrastructure, and automates common activities such as change requests, monitoring, patch management, security, and backup services. AMS enforces your corporate and security infrastructure policies and enables you to develop solutions and applications using your preferred development approach. (Image: docs.aws.amazon.com)

Switch to a cheaper region on AWS

Did you ever realize that costs can almost double between AWS regions? Yes, on AWS, not all regions are created equal! There are substantial differences in price, performance, number of AZs and product selection among AWS regions. However, if you have the privilege to switch to a cheaper region, you can save big in costs.

The US Regions Ohio, North Virginia and Oregon are the cheapest (based on S3, EC2, RDS and Lambda), followed by EU regions (e.g. Stockholm, Ireland and London), then the Asia Pacific AWS regions (e.g. Tokyo and Seoul), and finally South America (e.g. Sao Paulo) which is the most expensive (Image: openupthecloud.com)

Use AWS Batch for batch processing

AWS Batch allows you to run batch computing workloads on EC2 instances, taking advantage of unused compute capacity to reduce costs. AWS Batch can automatically launch and scale EC2 instances based on the size of your workload, allowing you to use the available capacity that would otherwise go to waste.

With AWS Batch, each Job Queue can be linked to one or more Compute Environnement that, with priority scheduling, distribute tasks of higher priorities to be executed on more than one Compute Environment. A Compute Environnement is responsible for dynamically launching and scaling compute resources based on task recruitments. (Image: firas.io)

Use AWS CloudFormation for infrastructure automation

AWS CloudFormation allows you to automate the creation and management of AWS resources. This can help optimize costs by reducing the time and effort required to manage infrastructure.

With CloudFormation, you can specify the exact resources you need and their respective sizes, enabling you to optimize your resource utilization and avoid overprovisioning or underutilization. CloudFormation templates can be used to define policies for cost optimization, such as scheduling resources to run only when needed, leveraging spot instances or reserved instances, and automating resource termination when they’re no longer needed. (Image: techgeeknext.com)

Use AWS Marketplace for software procurement

AWS Marketplace allows you to find and purchase software from third-party vendors. This can help reduce costs by providing access to a wide range of software at competitive prices.

AWS Marketplace has listed over 10,000 products from reputable and competitive vendors. You can choose from a variety of pricing models, such as pay-as-you-go, bring your own license (BYOL), and free trial, allowing you to avoid upfront costs and pay only for what you use. It also provides a range of software solutions and services, such as databases, analytics, and security, that can be easily deployed and integrated with your existing infrastructure, minimizing the need for additional hardware or software investments. (Image: aws.amazon.com)

✅ Use cost allocation tags

Cost allocation tags can help you track and manage your AWS costs by providing a detailed breakdown of spending by resource or team.

Your AWS resources can be tagged to designate the owner, the product line, or the operations team (Image: cloudbolt.io)

✅ Use AWS Budgets & Alerts

AWS Budgets helps you track your AWS costs and usage in real-time, set cost and usage alerts, and monitor and forecast your spending against your budget. It enables you to create custom budgets based on your business needs, and receive notifications when your costs or usage exceed a certain threshold. AWS Budgets can help you reduce costs by providing visibility into your spending patterns and enabling you to identify and address cost overruns or unexpected expenses in a timely manner.

From the Budgets dashboard, you can track how your budget portfolio is doing at a high level, as well as drill down into your budget details. (Image: aws.amazon.com)

✅ Use Cost Explorer

AWS Cost Explorer provides a visual representation of your AWS costs and usage over time, allowing you to analyze and optimize your spending patterns. It provides detailed reports and visualizations of your AWS costs, usage, and reservation utilization, and enables you to drill down into specific areas of spending to identify cost-saving opportunities.

AWS Cost Explorer can help you reduce costs by providing insights into your spending trends and identifying areas where you can optimize your resource utilization or purchase reserved instances to save costs. (Image: aws.amazon.com)

Conclusion

In conclusion, optimizing your AWS costs is an ongoing process that requires a combination of best practices, tools, and strategies. By following the tips and insights shared in this blog, you can reduce your cloud expenses while leveraging the best features on the cloud. Remember to regularly monitor your usage, adjust your resource utilization, and leverage the cost management tools provided by AWS to achieve optimal cost savings and efficiency. With a proactive approach to cost optimization, you can maximize the value of your AWS investment and achieve your business objectives.

Stay tuned for the next AWS tip. Until then, happy coding!

--

--

Platform Engineer
Platform Engineer

Published in Platform Engineer

Solving unanswered questions in high-scale web applications

Responses (2)