Save Money on AWS S3: Automate Storage Tiering with Terraform
Jenkins
Source: Dev.to | Jan 30, 2026 (UTC)
If you’re storing data in AWS S3, you’ve probably noticed that storage costs can add up quickly. The good news? You can significantly reduce these costs by automatically moving objects that haven’t been accessed in a while to cheaper storage tiers. In this article, I’ll show you how to implement S3 lifecycle policies using Terraform to do exactly that.
Understanding S3 Storage Classes
Before diving into the code, let’s quickly review the S3 storage classes and their use cases:
S3 Standard: For frequently accessed data (~$0.023/GB)
S3 Standard-IA (Infrequent Access): For data accessed less frequently (~$0.0125/GB)
S3 Intelligent-Tiering: Automatically moves data between tiers based on access patterns
S3 Glacier Instant Retrieval: For archive data with instant retrieval (~$0.004/GB)
S3 Glacier Flexible Retrieval: For archive data with retrieval times from minutes to hours (~$0.0036/GB)
S3 Glacier Deep Archive: Lowest cost for long-term archive (~$0.00099/GB)
The cost savings are substantial. Moving from Standard to Standard-IA saves about 46%, and moving to Glacier Deep Archive saves over 95%!
The Problem: Forgotten Data Costing You Money
Many organizations have S3 buckets filled with objects that were uploaded once and rarely (or never) accessed again. Examples include:
Old application logs
Backup files
Historical reports
Archived user uploads
Legacy project files
Without lifecycle policies, all this data sits in S3 Standard storage, costing you money unnecessarily.
The Solution: Terraform Lifecycle Policies
Let’s create a Terraform configuration that automatically transitions objects to cheaper storage tiers based on their age.
Basic Example: Simple Tiering Strategy
Here’s a straightforward lifecycle policy that moves objects through different storage tiers:
You can also use AWS Cost Explorer to track storage cost reductions over time.
Common Pitfalls to Avoid
Too Aggressive Transitions: Moving data to Glacier too quickly when it’s still being accessed incurs retrieval costs
Forgetting Minimum Storage Durations: Standard-IA and Glacier have minimum storage duration charges (30 days and 90 days respectively)
Ignoring Small Objects: Objects smaller than 128 KB are charged for 128 KB in IA and Glacier classes
Not Cleaning Up Incomplete Uploads: These can accumulate and cost money
Overlooking Noncurrent Versions: In versioned buckets, old versions can consume significant storage
Conclusion
Implementing S3 lifecycle policies with Terraform is one of the easiest ways to reduce your AWS bill without sacrificing data availability. By automatically transitioning infrequently accessed data to cheaper storage tiers, you can save thousands of dollars annually while maintaining compliance and data retention requirements.
Start with the examples in this article, adjust the transition periods to match your access patterns, and watch your storage costs drop. Your CFO will thank you!
Have you implemented S3 lifecycle policies in your infrastructure? What strategies have worked best for you? Share your experiences in the comments below!
For further actions, you may consider blocking this person and/or reporting abuse
Залишити відповідь