Created
June 24, 2020 11:53
-
-
Save eidosam/f9694a13ad32da5d7a4e1f7679a2ea11 to your computer and use it in GitHub Desktop.
List all secrets in AWS Secret Manager
This file contains hidden or 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 | |
from boto3.session import Session | |
session = Session() | |
for region_name in session.get_available_regions('secretsmanager'): | |
endpoint_url = f'https://secretsmanager.{region_name}.amazonaws.com' | |
client = session.client( | |
service_name='secretsmanager', | |
region_name=region_name, | |
endpoint_url=endpoint_url | |
) | |
next_token = None | |
while True: | |
try: | |
if next_token is not None: | |
api_response = client.list_secrets(NextToken=next_token) | |
else: | |
api_response = client.list_secrets() | |
for secret in api_response['SecretList']: | |
print(secret['ARN']) | |
if 'NextToken' not in api_response: | |
break | |
next_token = api_response['NextToken'] | |
except Exception as e: | |
print(e) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment