In AWS, one important lesson we can all learn is how they charge for bandwidth. This is often overlooked by developers, who are largely insulated financially from the effects of their decisions. AWS bandwidth costs can add up, but this is the case for GCP as well. Here are some useful tips and tricks to make your AWS bill lower and comply with best practices.
Don’t pay for bandwidth between AWS Services
For traffic between AWS compute services and other AWS services (s3, dynamo), with the right setup this traffic should be free. Since NAT Gateways incur bandwidth charges, make sure to use an Internet Gateway if the subnet is public (1). If you have compute instances in private subnets, ensure that traffic destined for internal AWS services goes through a Gateway Endpoint, since its free. This avoids a cost of ($.09 per GB). It may not seem like a lot, but depending on the amount of traffic you are receiving, this could add up to thousands of dollars.
Avoid inter-region data transfer
In AWS, If your ec2 instances are in us-west-2, and are uploading to a bucket that was created in us-east-1, you could be incurring some cost ($.02 per GB). A lot of Fortune 500 companies run everything in one account and one region, so this cost could apply to your company. Depending on traffic, it is better to split up the compute resources into different regions (use CDK/cloudformation), but they don't talk cross-region to other resources. This allows for failover DNS routing, and avoids this data charge. Alternatively, a quick and good solution is to have a read-only replica database in each region, instead of requesting across regions.
Keep Traffic within an availability zone
Each AWS Region consists of multiple zones for redundancy. Traffic that crosses an Availability Zone boundary typically incurs a data transfer charge. Use resources from the local Availability Zone whenever possible. Ensure that the database is deployed in each zone. If you are setting up a HPC cluster or ML Cluster, it could be in your best interest to deploy your ec2 instances in the same zone, if there is network traffic.
If you are using AWS Cloudfront, make sure to enable compression
It’s amazing how Youtube and Twitch offer their services for free. This comes at a huge cost each month, but they leverage their own infrastructure. As a startup or person seeking to host your own videos, you must keep a close eye on the costs per user. One saving grace, is that Netflix surely uses CDNs, and they surely have checked this very important box ‘Compress objects automatically’ (2). This reduces the network bandwidth by 80% and will also improve user experience by getting their content faster. In general, architecting a solution on AWS for VPNs or video hosting, can be very costly.
Use AWS Private link to share your endpoints within AWS
To connect to other microservices within the same company, create an endpoint service (3). The consumer, can then find your service when creating an interface endpoint, by inputting the id. This ensures that the routing will happen within the VPC and will not incur any data charge. This is better than VPC peering since there are less issues with conflicting private ip CIDRs and also you are able to share the load balancer if you associate a private dns name to it.
If you enjoyed this article, please follow and share with others!
Footnotes: