AWS GuardDutyをBoto3で有効化
AWS GuardDutyをGUIで有効化する場合、各リージョン毎でGUIによる
操作が必要(2019年5月時点)。
とても面倒なのでBoto3で自動的に有効化するスクリプトを書いた。
各リージョンのEC2を監視するコードにGuardDutyをEnableにする
コードに入れ替えただけ。
import boto3
ec2 = boto3.client('ec2')
regions = map(lambda x: x['RegionName'], ec2.describe_regions()['Regions'])
for region in regions:
if region == 'ap-northeast-1':
print('hello')
else:
client = boto3.client('guardduty', region_name=region)
print(region)
response = client.create_detector(
ClientToken='string',
Enable=True,
FindingPublishingFrequency='SIX_HOURS'
)
print(response)
その他
なぜかGUIで有効化した東京リージョン(ap-northeast-1)のみエラーを返すため
東京リージョンを除外している。