Created
August 4, 2022 09:02
-
-
Save PartTimeLegend/abe613e17be828085f169d9db0f358d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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