Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import boto3
  2. from botocore.exceptions import ClientError
  3.  
  4. topic_name = "EC2CreationTopic" # your Topic Name to delete in all regions
  5.  
  6. ec2 = boto3.client('ec2')
  7. sts = boto3.client("sts")
  8. account_id = sts.get_caller_identity()["Account"]
  9. regions = ec2.describe_regions().get('Regions', [])
  10. all_regions = [region['RegionName'] for region in regions]
  11.  
  12. for region in all_regions:
  13. client = boto3.client('sns', region_name=region)
  14. topic_arn = "arn:aws:sns:{}:{}:{}".format(region, account_id, topic_name)
  15. try:
  16. response = client.delete_topic(
  17. TopicArn=topic_arn
  18. )
  19. print("Deleted topic Id - {}".format(topic_arn))
  20. except ClientError as e:
  21. print("Resource not found in region - {}".format(region))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement