Get Secret from AWS Secrets Manager in Python

0 min read 51 words

You can store secrets in AWS Secret Manager and reference their ARN in AWS Systems Secret Manager.

The below snippet allows you to specify the associated parameter to get the secret value.

import boto3

ssm = boto3.client('ssm')
secretsmanager = boto3.client('secretsmanager')

parameter = ssm.get_parameter(Name="/your/parameter/name", WithDecryption=True)
secret = secretsmanager.get_secret_value(SecretId=parameter['Parameter']['Value'])
secret = json.loads(secret['SecretString'])

print(secret)
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags