Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LambdaでBilling Alertを拡張してみた

LambdaでBilling Alertを拡張してみた

JAWS-UG アーキテクチャ支部 クラウドネイティブ分科会#10
LT枠発表内容です。

Mamoru Ohashi

July 14, 2016
Tweet

More Decks by Mamoru Ohashi

Other Decks in Technology

Transcript

  1. 1 ⼤橋 衛(オオハシマモル) 1974/10/01(41歳) AWS Solution Architect(associate) アプリエンジニア12年 インフラエンジニア4年 クラウドエンジニア3年(=AWS歴)

    2016/07現在、現在⼤⼿通信会社にて AWSコンサル/セキュリティ監査業務 家族︓妻、娘2⼈ 趣味︓スノーボード、読書、DIY 絶賛本名プレイ中 @mamohacy http://blog.mamohacy.com/ ⾃⼰紹介 @mamohacy#20160714
  2. 7 Billingの課題 「予算策定は開発部⾨」 「⽀払とBilling Alert設定はAWSチーム」 p 各部⾨から予算情報を取得 p 予算情報/過去実績から閾値を算出・予測 p

    アカウントAにBilling Alertを設定 p アカウントBにBilling Alertを設定 p アカウントCに・・・・ p あ、Alert⾶んだ。確認しなきゃ。 p え︖負荷試験中だから⼤丈夫︖そうですか・・・ p は︖来週に緊急リリース︖マジっすか︖ @mamohacy#20160714
  3. 10 純正Billing Alert機能の特徴 Ø 親の介在が必須 Ø ⼦側が簡単に扱えない @mamohacy#20160714 純正Billing Alertの特徴

    ü要マネコン ü予算管理機能使えるのは親側だけ ü期間指定による閾値設定は出来ない üアラーム通知は閾値超過後の1回のみ
  4. 11 純正Billing Alert機能の特徴 Ø 親の介在は初期セットアップ時のみ Ø ⼦側が簡単に扱える @mamohacy#20160714 拡張版Billing Alertの特徴

    üマネコン不要 ü⼦側で設定ファイルを作りS3アップロードすればOK ü⽉初からの経過⽇数毎に閾値を設定可能(Max31段階) ü閾値超過時は設定直すまで1時間おきにアラーム通知
  5. 12 アーキテクチャ @mamohacy#20160714 S3 bucket User confi g set billing

    alarm reset alarm status Billing Alert CloudWatch email notification SNS upload invoke notify create 0:00/daily 0:00/hourly invoke invoke alarm アラーム状態の リセット Billing Alertの セット
  6. 13 config • ⽇毎に段階的に予算設定が可能 (最⼤31段階) • 実証実験中、負荷試験中、S-in、 キャンペーンなどのイベントに 合わせて予算を決め、ユーザー が⾃分⾃⾝でテキストファイル

    をS3に保存する • configファイルを置かなければ Alert処理は無効になる @mamohacy#20160714 #day, threshold(USD) 10, 200 20, 400 ・・・・ 31, 600 aws_budget.txt
  7. 15 ポイント その1 @mamohacy#20160714 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にセッ ト
  8. 16 ポイント その2 @mamohacy#20160714 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 閾値超えてれば即 座にアラームが発 生!