Skip to content

Instantly share code, notes, and snippets.

@maronavenue
Created November 15, 2020 16:23
Show Gist options
  • Save maronavenue/b8a7629f27c8896fef141ca5a6e730b7 to your computer and use it in GitHub Desktop.
Save maronavenue/b8a7629f27c8896fef141ca5a6e730b7 to your computer and use it in GitHub Desktop.
SSM Parameter Store Demo using Python SDK (boto3)
import boto3
import os
print("SSM Parameter Store Demo using Python SDK")
# TODO: Configure IAM role from basic Lambda execution to add read-only access to SSM
def lambda_handler(event, context):
ssm = boto3.client("ssm")
# TODO: Define your env var to manage different configurations such as environments
MY_ENV = os.environ["MY_ENV"]
# TODO: Copy sample test parameters below and create them on SSM Parameter Store (Note: Use SecureString for password)
raw_my_username = ssm.get_parameter(Name=f"/sandbox/{MY_ENV}/username")
raw_my_password = ssm.get_parameter(Name=f"/sandbox/{MY_ENV}/password", WithDecryption=True)
my_username = raw_my_username['Parameter']['Value']
my_password = raw_my_password['Parameter']['Value']
print(f"Username: {my_username}")
print(f"Password: {my_password}")
return f"Successfully fetched credentials on {MY_ENV} environment = {my_username}:{my_password}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment