Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created May 3, 2023 01:17
Show Gist options
  • Select an option

  • Save KyMidd/4b4e693681f585766cb2bf354014b006 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/4b4e693681f585766cb2bf354014b006 to your computer and use it in GitHub Desktop.
# Get GitHubPAT secret from AWS Secrets Manager that we'll use to start the githubcop workflow
def get_secret(secret_name, region_name):
# Create a Secrets Manager client
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=region_name
)
try:
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
except ClientError as e:
# For a list of exceptions thrown, see
# https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
print("Had an error attempting to get secret from AWS Secrets Manager:", e)
raise e
# Decrypts secret using the associated KMS key.
secret = get_secret_value_response['SecretString']
# Print happy joy joy
print("🚀 Successfully got secret", secret_name, "from AWS Secrets Manager")
# Return the secret
return secret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment