LoginSignup
4
4

More than 5 years have passed since last update.

DynamoDB の ThrottleEvent アラーム一括設定

Posted at

内容的には下記の EC2 に対しての設定と同じようなものだが…
http://qiita.com/web_se/items/8a969bd0d2aef1395272

DynamoDB のプロビジョンされたスループット超過のイベントである、ReadThrottleEvents/WriteThrottleEvents を通知してほしい。
該当メトリクスの CloudWatch アラームをまとめて設定する ruby スクリプトのサンプル

#!/usr/bin/env ruby

require 'aws-sdk'

dynamo = Aws::DynamoDB::Client.new(...) # set credentials for your env 
cw = Aws::CloudWatch::Client.new(...)

all_table_names = []
start_table = nil

while dynamo.list_tables(exclusive_start_table_name: start_table).next_page? do
  all_table_names += dynamo.list_tables(exclusive_start_table_name: start_table).table_names
  start_table = dynamo.list_tables.last_evaluated_table_name
end

target_names = all_table_names.select do |name|
  # 何か条件
end

target_names.each do |table_name|
  metrics = ['ReadThrottleEvents', 'WriteThrottleEvents'].each do |metric|
    puts "enable throttle alarm(#{metric}) to '#{table_name}'"
    cw.put_metric_alarm(
      {
        alarm_name: "#{table_name}-#{metric}",
        alarm_description: "#{table_name}-#{metric}",
        alarm_actions: [
          ..., # alarm action の ARN, 例えば SNS の "arn:aws:sns:ap-northeast-1:xxxxxxx:yyyyyyyy"
        ],
        metric_name: metric, namespace: 'AWS/DynamoDB',
        statistic: 'Sum',
        dimensions: [{name: 'TableName', value: "#{table_name}"}],
        period: 60, unit: 'Count',
        evaluation_periods: 1,
        threshold: 0,
        comparison_operator: 'GreaterThanThreshold',
      }
    )
    sleep 1 # API 制限回避…
  end
end

AWS CLI でもだいたい似た名前の呼び出しでできるはず。

4
4
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
4
4