コンテンツにスキップ

S3ライフサイクルポリシーで実現する段階的コスト削減

概要

S3 のライフサイクルポリシーを使い、オブジェクトの経過日数に応じてストレージクラスを自動的に移行することで、大幅なコスト削減が実現できる。Standard → Standard-IA → Glacier → Glacier Deep Archive という段階的な移行が基本パターン。

詳細

ストレージクラスと料金比較(東京リージョン 概算)

ストレージクラス GB/月 最低保存期間 取得料金
S3 Standard $0.025 なし なし
S3 Standard-IA $0.0138 30日 $0.01/GB
S3 Glacier Instant Retrieval $0.005 90日 $0.03/GB
S3 Glacier Deep Archive $0.002 180日 $0.02/GB

典型的なライフサイクルポリシー設定

{
  "Rules": [
    {
      "ID": "tiered-storage-lifecycle",
      "Status": "Enabled",
      "Filter": { "Prefix": "logs/" },
      "Transitions": [
        {
          "Days": 30,
          "StorageClass": "STANDARD_IA"
        },
        {
          "Days": 90,
          "StorageClass": "GLACIER"
        },
        {
          "Days": 365,
          "StorageClass": "DEEP_ARCHIVE"
        }
      ],
      "Expiration": {
        "Days": 2555
      }
    }
  ]
}

AWS CLI での適用

# ポリシーファイルをバケットに適用
aws s3api put-bucket-lifecycle-configuration \
  --bucket my-log-bucket \
  --lifecycle-configuration file://lifecycle.json

# 現在の設定確認
aws s3api get-bucket-lifecycle-configuration \
  --bucket my-log-bucket

Terraform での管理

resource "aws_s3_bucket_lifecycle_configuration" "logs" {
  bucket = aws_s3_bucket.logs.id

  rule {
    id     = "log_lifecycle"
    status = "Enabled"

    transition {
      days          = 30
      storage_class = "STANDARD_IA"
    }

    transition {
      days          = 90
      storage_class = "GLACIER"
    }

    expiration {
      days = 365
    }
  }
}

削減効果の試算

100GB のログデータを1年間保存する場合:

  • 移行なし(Standard のみ): $0.025 × 100 × 12 = $30/年
  • ライフサイクル適用後: $0.025×1ヶ月 + $0.0138×2ヶ月 + $0.005×9ヶ月 ≒ $10/年
  • 約67% の削減

なぜ重要か / いつ使うか

  • アクセス頻度が時間とともに下がるデータ(ログ、バックアップ、アーカイブ)に有効
  • AWS コスト最適化レビューで最初に確認すべき項目のひとつ
  • Standard-IA は最低30日保存の縛りがあるため、短命なオブジェクトには逆にコスト増になる点に注意
  • Glacier からの取り出しには時間(数分〜数時間)がかかるため、緊急復旧が必要なデータには不向き