Skip to content

Instantly share code, notes, and snippets.

@mda590
Last active July 7, 2022 12:23
Show Gist options
  • Save mda590/0b166129cf166c94b996472eafb51695 to your computer and use it in GitHub Desktop.
Save mda590/0b166129cf166c94b996472eafb51695 to your computer and use it in GitHub Desktop.
Get a Secure String parameter stored in the EC2 Systems Manager
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