Python programmers can utilise the boto3 library, which is the AWS SDK for Python, to read data from AWS Secrets Manager. An illustration of how to use boto3 to get a secret out of AWS Secrets Manager is shown below:
import boto3 import json # The first step is to create a client for the Secrets Manager service client = boto3.client('secretsmanager') # Get the secret value response = client.get_secret_value(SecretId='my-secret') secret_value = response['SecretString'] # The secret value (secret_value) is returned as a JSON string, # JSON you can parse it using json.loads secret_dict = json.loads(secret_value) # Access the data using the similar way you access the dictionary print(secret_dict['username']) print(secret_dict['password'])
The secret value, which is a JSON string, will be parsed into a dictionary by the following code, which will also build a client for the AWS Secrets Manager service. Then, you can get to the dictionary’s secret data.
Be aware that in order to use boto3, your computer must have the AWS SDK installed and setup. Using pip instal boto3, you may set up the AWS SDK. Additionally, in order to access the Secrets Manager service, your computer must be configured with the required AWS credentials.