Contents
1. コンソールで無料利用枠を確認する
| 手順 | 操作ポイント |
|---|---|
| ① | AWS マネジメントコンソール → Billing and Cost Management に移動 |
| ② | 左メニューの 「Free Tier」 をクリック |
| ③ | サービス別に 使用量 / 残量 / 有効期限 がリアルタイムで表示される |
- 使用量 が上限に近づくと画面右上に警告アイコンが出ます(自動メールは設定しない限り送信されません)。
- 有効期限 はアカウント作成日から 12 カ月で、残り期間は「Days remaining」欄に表示されます。
公式ドキュメント: https://docs.aws.amazon.com/ja_jp/awsaccountbilling/latest/aboutv2/tracking-free-tier-usage.html
2. CLI/SDK で無料利用枠の使用状況を取得する
2‑1. 必要な IAM ポリシー(最小権限)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ce:GetCostAndUsage", // Cost Explorer API "budgets:DescribeBudgets" // Budgets の設定参照(オプション) ], "Resource": "*" } ] } |
ce:GetCostAndUsage があれば、無料利用枠に関するデータを取得できます。
※IAM ポリシーは組織のガバナンスに合わせて Scope‑Down(サービス・リージョン限定)してください。
2‑2. AWS CLI の実行例
|
1 2 3 4 5 6 7 8 |
aws ce get-cost-and-usage \ --time-period Start=$(date -d '-30 days' +%Y-%m-%d),End=$(date +%Y-%m-%d) \ --granularity DAILY \ --filter '{"Dimensions": {"Key":"USAGE_TYPE","Values":["FreeTier"]}}' \ --metrics UsageQuantity \ --group-by Type=DIMENSION,Key=SERVICE \ --output json > free-tier-30days.json |
--filterの USAGE_TYPE = FreeTier が無料利用枠に限定した集計です。- 出力はサービスごとの日次使用量(単位は API が返す通り)になります。
2‑3. Boto3 (Python) サンプル
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import boto3 from datetime import datetime, timedelta client = boto3.client('ce') def get_free_tier_last_month(): end = datetime.utcnow().date() start = end - timedelta(days=30) resp = client.get_cost_and_usage( TimePeriod={'Start': str(start), 'End': str(end)}, Granularity='DAILY', Metrics=['UsageQuantity'], Filter={ 'Dimensions': { 'Key': 'USAGE_TYPE', 'Values': ['FreeTier'] } }, GroupBy=[{'Type':'DIMENSION','Key':'SERVICE'}] ) for result in resp['ResultsByTime']: date = result['TimePeriod']['Start'] for grp in result.get('Groups', []): svc = grp['Keys'][0] usage = float(grp['Metrics']['UsageQuantity']['Amount']) print(f"{date} | {svc:20s} : {usage}") if __name__ == "__main__": get_free_tier_last_month() |
- 注意点
- 無料利用枠の使用量は最大で 24 時間前 のデータが反映されます。リアルタイム性を求める場合は CloudWatch メトリクスと併用してください。
3. AWS Budgets で無料利用枠超過アラートを設定する
3‑1. 無料利用枠専用予算(Free Tier Budget)の作成手順
- Billing → Budgets を開く
- 「Create budget」→「Free tier」タイプを選択
- Budget amount は自動で無料枠上限が設定されます(サービスごとに個別)
- Thresholds(閾値) に以下を追加
| 閾値 | 通知先 | 推奨用途 |
|---|---|---|
| 85 % | SNS トピック / メール | 余裕がある段階での早期対応 |
| 100 % | SNS トピック / メール | 超過直前に緊急対策 |
- 「Review」→「Create budget」で完了
Budgets の公式ガイド: https://docs.aws.amazon.com/ja_jp/cost-management-budgets/latest/userguide/budgets-create.html
3‑2. SNS 通知の設定例(CLI)
|
1 2 3 4 5 6 7 8 9 |
# トピック作成 aws sns create-topic --name FreeTierAlert # メールサブスクリプション登録 aws sns subscribe \ --topic-arn arn:aws:sns:us-east-1:123456789012:FreeTierAlert \ --protocol email \ --notification-endpoint user@example.com |
Budget 作成時に取得したトピック ARN を Notification destination に貼り付ければ、設定完了です。
4. タグ付けでコスト可視化を強化する
4‑1. 推奨タグキー(最低3つ)
| キー | 用途例 |
|---|---|
Project |
プロジェクト名(例: my-webapp) |
Env |
環境(dev / staging / prod) |
Owner |
コストオーナーのメールアドレス |
4‑2. Cost Explorer のフィルタでタグを活用
- Cost Explorer → Reports → 「Create report」
- フィルタに Tag = Project : my-webapp と Usage Type = FreeTier* を設定
- 表示形式は「棒グラフ(サービス別)」+「テーブル(残量・有効期限)」
タグ付与のベストプラクティス: https://aws.amazon.com/jp/blogs/aws/tagging-best-practices/
4‑3. 自動タグ付与(例:AWS Service Catalog)
- Service Catalog のプロビジョニングテンプレートに「TagOptions」設定を追加すると、デプロイ時に必須タグが自動で付与されます。
- IAM ポリシーで
servicecatalog:TagOptionを許可し、不要なキーの付加を防止します。
5. 月次レポートと Zero‑Spend Budget の組み合わせ
5‑1. Cost Explorer の月次テンプレート
| 手順 | 内容 |
|---|---|
| ① | Cost Explorer → Reports → 「Create report」 |
| ② | 名前:Free Tier Monthly Summary |
| ③ | フィルタ:Tag Project = <対象プロジェクト>、Usage Type starts with FreeTier |
| ④ | グラフ:サービス別棒グラフ、表:残量・期限列 |
| ⑤ | 「Save as template」→「Auto‑email (CSV)」で毎月 1 日に配信設定 |
5‑2. Zero‑Spend Budget の作り方
- Budget type: Cost budget
- Budget amount:
0(Zero‑Spend) - Include: 「Free Tier usage」だけを対象にチェック
- Threshold: 100 % に SNS 通知を設定
この予算がアクティブになると、無料利用枠が完全に消費された瞬間に SNS がトリガーされます。実務上は「Zero‑Spend + Free Tier」組み合わせで「超過直前の最終警告」を実現できます。
詳細は AWS Cost Management の公式ページをご参照ください: https://docs.aws.amazon.com/ja_jp/cost-management/index.html
6. サービス別タイムゾーンと有効期限管理のポイント
| サービス | 計測タイムゾーン | 主な注意点 |
|---|---|---|
| EC2 | UTC | 月初リセットは UTC 基準なので、レポート作成時に「Time zone = UTC」を指定 |
| S3 | US‑East (N. Virginia) | データ転送量は日次で集計されるため、月跨ぎの増減を注意深く見る |
| Lambda | UTC | 呼び出し回数は 12 ヶ月単位でカウント。無料枠残量が急激に減少したら関数の最適化を検討 |
有効期限リマインダー例(CloudWatch Events + Lambda)
|
1 2 3 4 5 6 |
{ "source": ["aws.events"], "detail-type": ["Scheduled Event"], "scheduleExpression": "cron(0 9 ? * MON *)" } |
上記は毎週月曜 09:00 UTC にトリガーし、以下のような Lambda が SNS に期限30日前通知を送ります。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import boto3, datetime sns = boto3.client('sns') topic_arn = 'arn:aws:sns:us-east-1:123456789012:FreeTierAlert' def lambda_handler(event, _): acct_creation = datetime.datetime(2023, 4, 14) # 実際は STS GetCallerIdentity 等で取得 expiry = acct_creation + datetime.timedelta(days=365*1) days_left = (expiry - datetime.datetime.utcnow()).days if days_left <= 30: sns.publish( TopicArn=topic_arn, Subject='【AWS Free Tier】有効期限が近づいています', Message=f'残り {days_left} 日です。課金対象になる前にリソース整理をご検討ください。' ) |
まとめ
- コンソール の無料利用枠ページで日々の使用量と有効期限を確認
- CLI / Boto3 →
ce:GetCostAndUsageでスクリプト化し、レポートや自動通知に活用 - Budgets の Free Tier タイプで 85%・100% の閾値アラートを設定
- タグ付け を徹底して Cost Explorer の可視化を強化
- Zero‑Spend Budget + 月次テンプレート で超過リスクを自動的に検知し、期限前リマインダーで対策を遅延させない
これらの手順を組み合わせることで、AWS 無料利用枠の使用状況を リアルタイムかつ体系的に管理 でき、予期せぬ課金を未然に防げます。ぜひ自社環境に合わせて段階的に導入してください。