Last active
July 7, 2022 12:23
-
-
Save mda590/0b166129cf166c94b996472eafb51695 to your computer and use it in GitHub Desktop.
Get a Secure String parameter stored in the EC2 Systems Manager
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
def getParameter(param_name): | |
""" | |
This function reads a secure parameter from AWS' SSM service. | |
The request must be passed a valid parameter name, as well as | |
temporary credentials which can be used to access the parameter. | |
The parameter's value is returned. | |
""" | |
# Create the SSM Client | |
ssm = boto3.client('ssm', | |
region_name='us-east-2' | |
) | |
# Get the requested parameter | |
response = ssm.get_parameters( | |
Names=[ | |
param_name, | |
], | |
WithDecryption=True | |
) | |
# Store the credentials in a variable | |
credentials = response['Parameters'][0]['Value'] | |
return credentials |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment