in boto3_sample/s3_event_notifications_crawler_setup.py [0:0]
def set_sns_topic_policy(topic_arn, client, bucket_name):
try:
response = client.set_topic_attributes(
TopicArn=topic_arn,
AttributeName='Policy',
AttributeValue='''{
"Version": "2008-10-17",
"Id": "s3-publish-to-sns",
"Statement": [{
"Effect": "Allow",
"Principal": { "AWS": "%s" },
"Action": [ "SNS:Publish" ],
"Resource": "%s",
"Condition": {
"StringEquals": {
"AWS:SourceAccount": "%s"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:*:*:%s"
}
}
}]
}''' % (topic_arn, account_id,account_id,bucket_name)
)
return True
except botocore.exceptions.ClientError as e:
print_error(e)
return False