Skip to main content

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_IA after 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​

NameTypeDescription
regionstringAWS region where the target S3 bucket is located
bucket_namestringName of the existing S3 bucket to attach the lifecycle rule to
transition_daysnumberNumber of days after which objects should transition to STANDARD_IA
prefix_filterstring(Optional) Prefix filter for targeting specific object sets (e.g., "logs/")
environmentstringTag to specify the deployment environment (e.g., dev, staging, prod)

πŸ“€ Outputs​

NameDescription
bucket_nameThe name of the S3 bucket targeted
rule_idThe 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.