πŸ“Œ 10 tips to optimize cost πŸ’°πŸ’° in AWS πŸ“Œ

Prashant Lakhera
5 min readNov 20, 2022

--

πŸ“– To view the complete course https://lnkd.in/gjeGAPd2

➑️ You can contact me via https://lnkd.in/dePjvNDw

This is an old but gold meme, but no one wants to be in that spot 🀣. Here are 10 tips to save on AWS costs. This is not a complete list, please mention in the comment section what other steps we can take to save the AWS bill πŸ’΅.

β“΅ Stop unused instances: This is especially applied in pre-production. You can do it via an instance scheduler(https://aws.amazon.com/solutions/implementations/instance-scheduler-on-aws/) or boto3 with lambda (https://www.101daysofdevops.com/how-to-stop-start-ec2-instance-on-a-scheduled-basis-to-save-cost-by-using-boto3-and-lambda/).

β‘‘ Cleanup unused EBS volumes/Snapshots: Even after you terminate your EC2 instance, the EBS volume stays on. You need to delete it manually(unless delete on termination is set to true). These unattached EBS volumes will cost you money(https://github.com/100daysofdevops/100daysofdevops/blob/master/boto3/cleaning_old_ebs_vol/cleaning_old_ebs_vol.py). Similarly snapshot of your EBS volumes never got deleted and then continue to accumulate charges. Use tools like Data Lifecycle Manager(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/snapshot-ami-policy.html) and ensure setup retention based on Count/Age, i.e., how long you want to keep the snapshot. You can also clean up these snapshots using the boto3 script(https://github.com/100daysofdevops/100daysofdevops/blob/master/boto3/snapshot_cleanup/snapshot_cleanup.py).

β“· Right sizing the instance: Most companies performed Lift and shift migration from on-premise to AWS. The first instinct is to look at on-premise server configuration Memory/CPU and for equivalent ec2 instances. Sometimes, the on-premise server is over-provisioned, so if you moved your app to AWS, most of the time, it is utilized, but you pay the full price πŸ’°. On top of that, if the demand grows in the cloud, you can use features like auto-scaling or vertical scaling, which is hard to do or not available in an on-premise datacenter. AWS also provides a tool check this doc for more info https://aws.amazon.com/aws-cost-management/aws-cost-optimization/right-sizing/

β‘£ Use Reserved Instance(RI)/Spot Instance/Saving Plans: RI provides a significant discount compared to on-demand pricing. You can use convertible RI, which offers a 45% discount, but you have the flexibility to change instance families. There is one caveat whether you use these instances or not, you need to pay AWS as there is a commitment of 1 or 3 years. Also, remember downgrading the convertible instance is no longer possible, but you can sell it in AWS Marketplace. Spot instances offer up to a 90% discount to use spare capacity. You can use a spot instance if your workload is interruptible. If the same instance is required for Reserved/On-demand capacity, the spot instance will be terminated with a 2-min notice. Saving plans offer a discount if you commit for 1–3 years to services like EC2, Lambda, and Fargate. Once you go with the savings plan, you will pay an hourly on-demand rate. But the discount will be applied at the billing stage after AWS confirms your total spend. Also, you cannot sell a saving plan in the AWS marketplace.

β‘€ Create a billing alarm to monitor your AWS charges: You can monitor your AWS charges by creating a billing alarm using CloudWatch. It will trigger an alarm once the billing threshold reach. You can then integrate it with SNS to trigger a notification https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html

β‘₯ S3 intelligent tiering: The advantage of using S3 intelligent tiering, you don’t need to move objects manually from one tier to another; S3 intelligent tiering does this for you. Objects that are frequently accessed are moved back to the frequent access tier. There are no retrieval fees for accessing objects, but this tier has a monitoring and automation cost per 1000 objects. So use this class if you have long-lived data with changing or unknown patterns.

⑦ Use of Lambda function: You can use the Lambda function as it follows pay as you go model. But if you are dealing with a legacy application, consider how much effort is required to convert it into a Lambda equivalent.

⑧ Use of AWS Cost explorer: You can use AWS cost explorer to check your bill for top spend line items. Then you decide on resources to see if they are required. Cost explorer also helps you to forecast your expenses over the following 12 months.

⑨ Analyze AWS data transfer cost: This is one hidden factor, and trust me, this will become a major culprit. This is one unknown territory. As for the other factor like EC2 instance and S3 bucket cost, we can calculate upfront, but how much is data cost will depend upon how much our customer uses the application, regional data transfer. You can use AWS cost explorer to narrow down the data transfer cost or to understand the cost associated with Internet outbound(in AWS, there is no inbound cost), inter-Availability Zone, or inter-Region data transfers, as well as which environment these costs occurred in. Check the blog for more info https://aws.amazon.com/blogs/mt/using-aws-cost-explorer-to-analyze-data-transfer-costs/. If you are using the NAT gateway, check whether the instance is sending traffic in the same AZ as the NAT gateway. Else, setup the NAT gateway per availability zone to reduce cross-AZ data transfer charges. Also, for AWS services like S3, DynamoDB setup gateway and interface VPC endpoints to route traffic through these endpoints rather than using NAT gateway. There are no data processing or hourly charges for using VPC endpoints. https://aws.amazon.com/premiumsupport/knowledge-center/vpc-reduce-nat-gateway-transfer-costs/

πŸ”Ÿ Stop any unused RDS instance: I was unaware of this feature, and yes, you can stop your RDS instance temporarily(7 days) to save cost. If you don’t manually start your DB instance after seven days, then the instance is automatically started. This happens so that the instance doesn’t fall behind on any required maintenance updates for the hardware, underlying operating system, or database engine version. For more info, check this doc https://aws.amazon.com/premiumsupport/knowledge-center/rds-stop-seven-days/. You can use instance scheduler to automate this process (https://aws.amazon.com/solutions/implementations/instance-scheduler-on-aws/). You can also purchase a reserve RDS instance similar to EC2 to get a significant discount for a one or three year term https://aws.amazon.com/rds/reserved-instances/. Catch with this once you commit RI, and in the future, you decide not to use you can’t sell it in the marketplace https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ri-market-general.html

Reference:

--

--

Prashant Lakhera
Prashant Lakhera

Written by Prashant Lakhera

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP

No responses yet