import boto3
iam_client = boto3.client('iam')
role_name = 'eventbridge-to-sns-role'
trust_policy = { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "events.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }
response = iam_client.create_role( RoleName=role_name, AssumeRolePolicyDocument=json.dumps(trust_policy) )
policy_name = 'eventbridge-to-sns-publish'
policy = { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "sns:Publish" ], "Resource": "*" } ] }
response = iam_client.create_policy( PolicyName=policy_name, PolicyDocument=json.dumps(policy) )
policy_arn = response['Policy']['Arn']
iam_client.attach_role_policy( RoleName=role_name, PolicyArn=policy_arn )
aws events put-events --entries file://events.json
aws sns publish --topic-arn arn:aws:sns:us-east-1:123456789012:my-topic --message "test"