Quick hacks to bring down EC2 instances cost drastically

Banner

When utilizing a cloud environment, optimizing costs and maximizing resource utilization are crucial considerations. This is particularly important for teams and organizations that rely on Amazon Web Services (AWS) Compute and Relational Database Service (RDS) Instances, as scalability of compute and databases is essential to accommodate growing demands. While options like adding additional servers behind a load balancer or upgrading instance types to larger sizes exist, it's important to note that taking advantage of reserved instances becomes challenging when the flexibility to dynamically change instance types is desired.

EC2 Instance Cost Optimization

AWS offers a variety of instance types within the general category, with the t2.micro series being commonly available for the Free Tier. However, for organizations utilizing general purpose Linux EC2 instances, it is advisable to transition from the t2 series to the t3 series once the free tier or tier hours have been utilized. This switch allows organizations to continue benefiting from cost-effective options while accommodating their computing needs effectively.

EC2 pricing

The advantages of leveraging the t3 series over the t2 series are evident from the pricing table provided. Not only is the t3 series more cost-effective, but for nano, micro, and small instances, it offers 2 vCPUs instead of just 1 vCPU. Additionally, the t3 series provides faster network performance, making it a superior option in terms of both cost and machine capabilities.

To take advantage of the t3 series, a simple process requiring approximately five minutes of downtime per EC2 instance can be followed. The steps involve stopping the instance, clicking on "change instance type," selecting the equivalent t3 size, and starting the server again. However, it's important to note that if the server doesn't have an Elastic IP address assigned, the Public IP address will change, while the private IP address remains unchanged.

Moreover, for applications that rely on technologies providing binaries for arm processors, setting up a new server with the t4g series is recommended. This transition involves migrating the workload from the t2/t3 to the t4g server. The t4g series offers roughly half the cost of the t3 series while delivering better performance.

According to AWS, PHP performance is 30% better on a t4g instance compared to the t3 series, as per the provided comparison.

What works on t4g arm64 processors?

  • Java
  • Golang
  • PHP
  • WordPress
  • ERPNext
  • Ghost CMS
  • Strapi CMS
  • GitLab
  • GitLab Runner
  • MongoDB

On-demand Pricing v/s other cost optimization options

Many users opt for on-demand servers when they are uncertain about the need for a larger server to handle increased loads. In such scenarios, the Compute Savings Plan can be a suitable alternative to reserved instances.

If a project or organization can confidently determine the number of EC2 instances required, choosing the Compute Savings Plan becomes a logical choice. This approach provides flexibility to change EC2 instance types, terminate and create new servers as needed, while benefiting from a price commitment to spend on EC2 instances per hour for Compute Power.

To leverage the Compute Savings Plan, users can calculate the per hour cost of all the instances they require based on the Savings Plan rate and sign up for it through the Billing dashboard in the AWS Console. As illustrated in the table below, Savings Plan prices are nearly 27% cheaper, resulting in significant cost reductions. In simpler terms, by utilizing the Compute Savings Plan, the cost of a fifth server is saved for every four servers deployed.

EC2 pricing

If a specific series of EC2 instances is being used, let’s say t3, then there’s an option to commit on per hour usage of EC2 instances by series. It’s possible to change instance type within the series, leading to a cost reduction of up to 37%. So, every two servers help cover the cost of a third one.

EC2 pricing

When calculating the hourly rate of the instances, account for how many hours the servers are kept up. During non-active hours, the non-production servers can be powered down.

EBS Volume Cost Optimization

By default, when creating an EBS Volume in AWS, the volume type is set to gp2. However, it is worth noting that gp3 volumes offer a more cost-effective and faster alternative to gp2 volumes. The new gp3 volumes provide a baseline performance of 3,000 IOPS and 125 MB/s at any volume size.

According to AWS, gp3 volumes deliver SSD-like performance at a 20% lower cost per GB compared to gp2 volumes. Additionally, by decoupling storage performance from capacity, gp3 volumes allow for easy provisioning of higher IOPS and throughput without the need for additional block storage capacity. This improves overall performance while reducing costs.

Changing EBS Volumes from gp2 to gp3 is a straightforward process that does not require any downtime. Simply follow these steps in the AWS Console: go to EC2, navigate to EBS, select the desired EBS Volume, click on "Actions," choose "Modify Volume," and change the Volume type to gp3. AWS will charge a one-time cost for the data copying involved, but in the long run, significant savings can be achieved due to the 20% cheaper pricing and improved performance provided by gp3 volumes.

References

https://aws.amazon.com/ec2/pricing/on-demand/ https://aws.amazon.com/savingsplans/compute-pricing/