CloudFrontでコンテンツ配信を高速化
予定コスト: $0.00(設定のみ)
✅ この記事でやること
S3前段にCloudFrontを配置してHTTPS化とキャッシュ導入。
✅ 前提(準備)
S3静的サイトが公開済み。
図解:配信フロー
HTTPS強制とキャッシュのイメージ。
Client
→ CloudFront (HTTPS, global edge cache)
→ S3 Origin
Distribution作成(最小)
最小のDistributionConfigを作成してデプロイ。
cat > cf.json <<JSON
{
"CallerReference": "advent-$(date +%s)",
"Origins": {
"Quantity": 1,
"Items": [{
"Id": "s3-origin",
"DomainName": "${BUCKET}.s3.amazonaws.com",
"S3OriginConfig": { "OriginAccessIdentity": "" }
}]}
},
"DefaultCacheBehavior": {
"TargetOriginId": "s3-origin",
"ViewerProtocolPolicy": "redirect-to-https",
"AllowedMethods": { "Quantity": 2, "Items": ["GET", "HEAD"] }
},
"Enabled": true
}
JSON
aws cloudfront create-distribution --distribution-config file://cf.json
💡 豆知識 (Tips)
- PriceClassの選定でコスト最適化(国内中心なら100で十分)
- OACでS3非公開+CloudFront経由のみ公開
⚠️ 落とし穴
- Invalidation濫用による課金増
- 認証前提のコンテンツをパブリック配信
🧾 今日のコスト
$0.00(設定のみ)
✅ まとめ
- 本日のゴールを確認
- 無料枠を意識して運用
- 次回に繋がるポイントを整理
✅ 次回予告(15日目)
「コストエクスプローラーで料金を見える化」