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?

More than 3 years have passed since last update.

ElastAlertでアラート通知先にAWS SNSを使った時のメモ

Last updated at Posted at 2020-04-25

ドキュメントの記載が古かった

実際は

・sns_topic_arnとaws_region
 現在もこの設定でOK
・aws_access_key
 aws_access_key_idになっていた
・aws_secret_key
 aws_secret_access_keyになっていた
・profile
 試していないが、ソースコードみた感じでは「aws_profile」になっているようだった

sns_topic_arn: The SNS topic’s ARN. For example, arn:aws:sns:us-east-1:123456789:somesnstopic

Optional:

aws_access_key: An access key to connect to SNS with.

aws_secret_key: The secret key associated with the access key.

aws_region: The AWS region in which the SNS resource is located. Default is us-east-1

profile: The AWS profile to use. If none specified, the default will be used.

動作する設定の書き方

以下のように「aws_region」だけsnsにネストした形で書かないとうまく動かなかった。理由は以下のissueに参照。
SNS alert ERROR #674

alert:
  - sns:
      # example, aws_region: "ap-northeast-1"
      aws_region: "~aws region name~"
# example, arn:aws:sns:us-east-1:123456789:somesnstopic
sns_topic_arn: "arn:aws:sns:~aws region name~:~id~:~topic name~"
aws_access_key_id: "~my access key~"
aws_secret_access_key: "~my secret key~"

ちなみに実際に設定した値ではありません。動かす環境で違う設定になるので、動かす環境の値を指定してください。

aws_profileの使い方が間違っている(2020/5/10追記)

alerts.pyがバグっている。
profileを使う場合、aws_access_key_id、aws_secret_access_key、regionを外部ファイルであるprofileに記載できる。
ただし、現在の実装ではaws_access_key_id、aws_secret_access_key、region、profileをすべて指定する前提になっている。
profileがどういうものか理解していれば、以下の修正案のような実装になるはずなのである。

修正前

alerts.py(対象のコードのところ(948~956行目))
    def alert(self, matches):
        body = self.create_alert_body(matches)

        session = boto3.Session(
            aws_access_key_id=self.aws_access_key_id,
            aws_secret_access_key=self.aws_secret_access_key,
            region_name=self.aws_region,
            profile_name=self.profile
        )

修正案

alerts.py(対象のコードのところ(948~956行目))
    def alert(self, matches):
        body = self.create_alert_body(matches)

        if self.profile is None:
            session = boto3.Session(
                aws_access_key_id=self.aws_access_key_id,
                aws_secret_access_key=self.aws_secret_access_key,
                region_name=self.aws_region
            )
        else:
            session = boto3.Session(profile_name=self.profile)

# Create ~/.aws/credentials

[default]
aws_access_key_id = xxxxxxxxxxxxxxxxxxxx
aws_secret_access_key = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

# Create ~/.aws/config

[default]
region = us-east-1

# alert rule setting

alert:
  - sns
sns_topic_arn: "arn:aws:sns:~aws region name~:~id~:~topic name~"
aws_profile: "default" # profile name
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?