S3 Lifecycle to Infrequent Access
π¦ Overviewβ
This Terraform module applies an Amazon S3 lifecycle policy to an existing bucket. The policy automatically transitions objects to the STANDARD_IA (Infrequent Access) storage class after a configurable number of days (default: 30).
Itβs ideal for buckets storing logs, cold archive data, or infrequently accessed backups.
β Key Featuresβ
- Automates object tiering to
STANDARD_IAafter a set number of days - Supports optional prefix filtering for targeted transitions
- Reduces S3 storage costs with no manual intervention
- Designed to apply to any existing S3 bucket
πΌ Use Casesβ
- Archive log storage with delayed cold-tier transition
- Backup data stored long-term with reduced retrieval frequency
- General cold data tiering in large S3 buckets
- Billing optimization for compliance data and audit logs
π₯ Input Variablesβ
| Name | Type | Description |
|---|---|---|
| region | string | AWS region where the target S3 bucket is located |
| bucket_name | string | Name of the existing S3 bucket to attach the lifecycle rule to |
| transition_days | number | Number of days after which objects should transition to STANDARD_IA |
| prefix_filter | string | (Optional) Prefix filter for targeting specific object sets (e.g., "logs/") |
| environment | string | Tag to specify the deployment environment (e.g., dev, staging, prod) |
π€ Outputsβ
| Name | Description |
|---|---|
| bucket_name | The name of the S3 bucket targeted |
| rule_id | The ID of the applied lifecycle rule |
π Deployment Readinessβ
- β Compatible with Terraform 1.0+
- β Tested with AWS provider 5.x
- π§ͺ Requires an existing S3 bucket and IAM permissions to manage lifecycle rules
π οΈ Example Usageβ
module "s3_lifecycle_ia" {
source = "git::ssh://git@github.com/archiphire/aws-level-1-modules.git//storage/s3-lifecycle-ia?ref=v1.0.0"
region = "us-east-1"
bucket_name = "archiphire-cold-archive"
transition_days = 30
prefix_filter = "logs/"
environment = "prod"
}
terraform init
terraform plan
terraform apply
or
tofu init
tofu plan
tofu apply
π§Ή Cleanup Optionsβ
Terraform Destroy (for test environments):
terraform destroy
or
tofu destroy
β οΈ This will only remove the lifecycle rule. The S3 bucket and all objects will remain unless manually deleted.
π‘οΈ Notesβ
This is a Level 1 cost-optimization module designed for modular use. To extend functionality, consider chaining with:
s3-access-logging s3-secure-bucket
π Deployment Package Noticeβ
This module is part of the Level 1 AWS License Tier. To access the full deployment package and source code, subscribe to Archiphire.