Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created January 13, 2025 03:56
Show Gist options
  • Select an option

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

Select an option

Save KyMidd/f490d911ff191d756a172ec910023b99 to your computer and use it in GitHub Desktop.
# Get the secret using the SSM lambda layer
def get_secret_ssm_layer(secret_name):
secrets_extension_endpoint = "http://localhost:2773/secretsmanager/get?secretId=" + secret_name
# Create headers
headers = {"X-Aws-Parameters-Secrets-Token": os.environ.get('AWS_SESSION_TOKEN')}
# Fetch secret
try:
secret = requests.get(secrets_extension_endpoint, headers=headers)
except requests.exceptions.RequestException as e:
print("Had an error attempting to get secret from AWS Secrets Manager:", e)
raise e
# Print happy joy joy
print("🚀 Successfully got secret", secret_name, "from AWS Secrets Manager")
# Decode secret string
secret = json.loads(secret.text)["SecretString"] # load the Secrets Manager response into a Python dictionary, access the secret
# Return the secret
return secret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment