Upload
mamoru-ohashi
View
699
Download
4
Embed Size (px)
Citation preview
Mamoru Ohashi@mamohacy
@mamohacy#20160714
Lambda で Billing Alert を拡張してみた
~ 非マネコン / 日別 31 段階 / 無期限繰返通知 ~
2016.07.14
@mamohacy#20160714 2
大橋 衛 ( オオハシマモル )1974/10/01(41 歳 )AWS Solution Architect(associate)
アプリエンジニア 12 年インフラエンジニア 4 年クラウドエンジニア 3 年 (=AWS 歴 )2016/07 現在、現在大手通信会社にてAWS コンサル / セキュリティ監査業務
家族:妻、娘2人趣味:スノーボード、読書、 DIY
絶賛本名プレイ中
@mamohacy
http://blog.mamohacy.com/
自己紹介
@mamohacy#20160714 3
AWS Summit Tokyo 2016 に登壇しました
http://cloudblog.kddi.com/iaaspaas/4279/
使ってますか?Lambda
使ってますよ!Lambda
@mamohacy#20160714 6
使ってますよ! Lambda
うちでは主に「運用管理ツール」として使ってます
・ Slack に投げた勤怠連絡をメールに転送・ billing 情報を Slack に通知・ IAM 管理統制とセキュリティ統制自動化・侵入テスト申請自動化・などなど
その中から今回は「拡張版 Billing Alert 」をご紹介!
@mamohacy#20160714
開発部門 Y開発部門 X
支払アカウント
弊社の AWS 利用費支払い管理
システムA
開発
商用
検証
システム B
開発
システム C
開発 / 検証商用
AWSチーム
開発部門
:AWS アカウント
@mamohacy#20160714 8
Billing の課題
「予算策定は開発部門」「支払と Billing Alert 設定は AWS チーム」
各部門から予算情報を取得 予算情報 / 過去実績から閾値を算出・予測 アカウント A に Billing Alert を設定 アカウント B に Billing Alert を設定 アカウント C に・・・・ あ、 Alert 飛んだ。確認しなきゃ。 え?負荷試験中だから大丈夫?そうですか・・・ は?来週に緊急リリース?マジっすか?
@mamohacy#20160714
やってられるかァ!
@mamohacy#20160714
ってことでBilling Alert を Lambda で
拡張してみました
@mamohacy#20160714 11
純正 Billing Alert 機能の特徴
親の介在が必須 子側が簡単に扱えない
純正 Billing Alert の特徴要マネコン予算管理機能使えるのは親側だけ期間指定による閾値設定は出来ないアラーム通知は閾値超過後の1回のみ
@mamohacy#20160714 12
純正 Billing Alert 機能の特徴
親の介在は初期セットアップ時のみ 子側が簡単に扱える
拡張版 Billing Alert の特徴マネコン不要子側で設定ファイルを作り S3 アップロードすれば OK月初からの経過日数毎に閾値を設定可能 (Max 31段階 )閾値超過時は設定直すまで 1 時間おきにアラーム通知
@mamohacy#20160714 13
アーキテクチャ
S3 bucket
User
config
set billing alarm
reset alarm status
Billing Alert
CloudWatchemail
notification SNS
upload invoke
notify
create
0:00/daily
0:00/hourl y
invoke
invoke
alarm
アラーム状態のリセット
Billing Alert のセット
@mamohacy#20160714 14
config• 日毎に段階的に予算設定が可能
(最大 31 段階)• 実証実験中、負荷試験中、 S-
in 、キャンペーンなどのイベントに合わせて予算を決め、ユーザーが自分自身でテキストファイルを S3 に保存する
• config ファイルを置かなければAlert処理は無効になる
#day, threshold(USD)10, 20020, 400・・・・31, 600
aws_budget.txt
@mamohacy#20160714
reset-alarm-status.py set-billing-alarm.py
コア・プログラム
43 steps(*include comments) 183 steps(*include comments)
@mamohacy#20160714 16
ポイント その1
cw_alarm_description = cw_alarm_description.replace("%THRESHOLD%", threshold)cw_alarm_action = cw_alarm_action.replace("%ACCOUNT_ID%", account_id) #Alarm の設定response = cloud_watch.put_metric_alarm(AlarmName=cw_alarm_name,
AlarmDescription=cw_alarm_description,ActionsEnabled=True,AlarmActions=[cw_alarm_action], Namespace=cw_metric_namespace,
MetricName=cw_metric_name, Statistic='Maximum',
Dimensions=[ {'Name': 'Currency’, 'Value': 'USD’}, {'Name': 'LinkedAccount’, 'Value': account_id } ],
Period=21600, EvaluationPeriods=1, Threshold=int(threshold), ComparisonOperator='GreaterThanThreshold'
)
set-billing-alarm.py
config から読んだ閾値を alarmにセット
@mamohacy#20160714 17
ポイント その2
alarm_name="Estimated Charges”
# 実施要否判定 () response = cloud_watch.describe_alarms(AlarmNames=[alarm_name],
StateValue='ALARM’)
if len(response['MetricAlarms']) <= 0:return 0
# アラームステータスをリセット(強制的にアラームじゃない状態に戻す)response = cloud_watch.set_alarm_state(AlarmName=alarm_name,
StateValue='INSUFFICIENT_DATA',StateReason='’,StateReasonData='{}’)
return 0
reset-alarm-status.py
閾値超えてれば即座にアラームが発生!
@mamohacy#20160714 18
拡張版 Billng Alert の導入効果
親による一括予算管理が不要に有効化 / 無効化の設定も子側でAlert 通知後の判断も子側からスタート
(設定修正漏れ /恣意的 /バグ /障害 etc... )
親アカウント側の予算管理& BillingBurst対応工数が
「実質ゼロ」 に!
@mamohacy#20160714
ご清聴ありがとうございました!