Interview Prep/Python for DevOps/boto3 & AWS automation

How do you read secrets from AWS Secrets Manager or SSM Parameter Store?

IntermediateConceptboto3 & AWS automation
Answer
sm = boto3.client("secretsmanager")
secret = json.loads(sm.get_secret_value(SecretId="prod/db")["SecretString"])

ssm = boto3.client("ssm")
token = ssm.get_parameter(Name="/ops/slack/token", WithDecryption=True)["Parameter"]["Value"]

Cache secrets in memory for the process lifetime (or with a TTL) rather than fetching per request; both APIs are priced and throttled. AWS provides aws-secretsmanager-caching for this. Never write secrets to disk or logs.

All Python for DevOps questions Roadmap: Python for automation

More on boto3 & AWS automation