Created
October 1, 2022 17:36
-
-
Save beabetterdevv/1bf0a0f0f2b77c24dc37bf292c5df9a1 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
IAM Policies | |
--- | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "VisualEditor0", | |
"Effect": "Allow", | |
"Action": "secretsmanager:GetSecretValue", | |
"Resource": "*" | |
} | |
] | |
} | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "VisualEditor0", | |
"Effect": "Allow", | |
"Action": "kms:Decrypt", | |
"Resource": "*" | |
} | |
] | |
} | |
Lambda Code | |
--- | |
import json | |
import boto3 | |
import base64 | |
# Your secret's name and region | |
secret_name = "custom-managed-secret" | |
region_name = "us-east-1" | |
#Set up our Session and Client | |
session = boto3.session.Session() | |
client = session.client( | |
service_name='secretsmanager', | |
region_name=region_name | |
) | |
def lambda_handler(event, context): | |
# Calling SecretsManager | |
get_secret_value_response = client.get_secret_value( | |
SecretId=secret_name | |
) | |
#Raw Response | |
print(get_secret_value_response) | |
#Extracting the key/value from the secret | |
secret = get_secret_value_response['SecretString'] | |
print(secret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment