0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

6日目:AWS無料枠使い倒し「S3で静的Webサイト公開」

0
Last updated at Posted at 2025-12-05

S3でストレージを構築:静的Webサイト公開

予定コスト: $0.00(無料枠内)


✅ この記事でやること

静的WebサイトをS3で公開し、URLを確認します。


✅ 前提(準備)

ユニークなバケット名、東京リージョン。


バケット作成

リージョン指定で作成。

REGION=ap-northeast-1
BUCKET=my-static-site-$RANDOM
aws s3api create-bucket --bucket $BUCKET --region $REGION 
  --create-bucket-configuration LocationConstraint=$REGION

ファイルアップロードとサイト有効化

HTMLアップロード→静的Webサイト有効化。

cat > index.html <<'EOF'
<!doctype html><html><body><h1>Hello S3 Static Site</h1></body></html>
EOF
aws s3 cp index.html s3://$BUCKET/index.html
aws s3 website s3://$BUCKET --index-document index.html --error-document error.html

公開設定(GetObjectのみ)

Public Readをポリシーで許可。

aws s3api put-public-access-block --bucket $BUCKET 
  --public-access-block-configuration 'BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false'
cat > policy.json <<'JSON'
{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "PublicReadGetObject",
    "Effect": "Allow",
    "Principal": "*",
    "Action": ["s3:GetObject"],
    "Resource": "arn:aws:s3:::${BUCKET}/*"
  }]
}
JSON
aws s3api put-bucket-policy --bucket $BUCKET --policy file://policy.json

サイトURL確認

Websiteエンドポイントを出力。

echo "http://$BUCKET.s3-website-$REGION.amazonaws.com"

💡 豆知識 (Tips)

  • HTTPSが必要ならCloudFront(Day 14)で対応
  • アクセスログを有効にして利用状況を把握

⚠️ 落とし穴

  • バケット一覧や大量PUT/GETによる無料枠超過
  • 誤ってオブジェクト削除→バージョニング無しで復旧不可

🧾 今日のコスト

$0.00(無料枠内)


✅ まとめ

  • 本日のゴールを確認
  • 無料枠を意識して運用
  • 次回に繋がるポイントを整理

✅ 次回予告(7日目)

「CloudWatchで監視の基本を押さえる」

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?