Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created August 7, 2022 14:43
Show Gist options
  • Select an option

  • Save KyMidd/54a3585eedc8e477b5f8ea94f61d4987 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/54a3585eedc8e477b5f8ea94f61d4987 to your computer and use it in GitHub Desktop.
# Find all secrets that match string
def search_for_secrets(SecretSearchString, SecretSearchRegion):
secret_search_string = SecretSearchString
secret_search_region = SecretSearchRegion
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=secret_search_region,
)
try:
list_secrets_response = client.list_secrets(
MaxResults=100, #100 is max supported
Filters=[
{
'Key': 'name',
'Values': [
secret_search_string,
]
},
]
)
except ClientError as e:
print("The requested secret search string returned no results: " + secret_search_string)
print("The error is:", e)
else:
# Store all secrets in array:
foundSecrets = []
for secret_name in list_secrets_response["SecretList"]:
#print("Found secrets:", secret_name["Name"])
foundSecrets.append(secret_name["Name"])
#print("The list of secrets is: ", foundSecrets)
return(foundSecrets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment