ドキュメントの記載が古かった
実際は
・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がどういうものか理解していれば、以下の修正案のような実装になるはずなのである。
修正前
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
)
修正案
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