Skip to content

Instantly share code, notes, and snippets.

@PartTimeLegend
Created August 4, 2022 09:02
Show Gist options
  • Save PartTimeLegend/abe613e17be828085f169d9db0f358d1 to your computer and use it in GitHub Desktop.
Save PartTimeLegend/abe613e17be828085f169d9db0f358d1 to your computer and use it in GitHub Desktop.
import json, botocore
from boto3.session import Session
def serialize_sets(obj):
if isinstance(obj, set):
return list(obj)
return obj
s = Session()
regions = s.get_available_regions('lambda')
enabled_regions = set()
for region in regions:
sts_client = s.client('sts', region_name=region)
try:
sts_client.get_caller_identity()
enabled_regions.add(region)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "InvalidClientTokenId":
pass
else:
raise
print(json.dumps(enabled_regions, default=serialize_sets))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment