-
-
Save KyMidd/f490d911ff191d756a172ec910023b99 to your computer and use it in GitHub Desktop.
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
| # 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