I'm automating cloudtrail creation in multiple accounts using python boto3. My issue is that create_trail doesn't automatically create the sns topic to associate with the trail. create_trail expects the sns topic to already exist.
I can create the sns topic with boto, but I can't seem to set the policy for the topic to allow cloudtrail to publish to the topic.
This is what the correct policy looks like in the console:
{
"Sid": "AWSCloudTrailSNSPolicy20150319",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:123456678912:us-east-1-trail"
}
There doesn't seem to be a way to give permissions to a service with boto:
client.add_permission(
TopicArn=arn,
Label='AWSCloudTrailSNSPolicy20150319',
AWSAccountId=[
'12345678912'
],
ActionName=[
'Publish',
]
)
If I add the account here the create_trail call still fails with:
An error occurred (InsufficientSnsTopicPolicyException) when calling the CreateTrail operation: SNS Topic does not exist or the topic policy is incorrect!
Is there a way to just give permissions to a service or to automatically set this when creating the trail or sns topic?