Search

Monday 29 April 2019

AWS Secrets Manager python script

"Introduction to AWS Secrets Manager"
https://www.aws.training/learningobject/video?id=19441
The link above is to a 15 minute introductory video that covers the "AWS Secrets Manager" service.
The summary from this training and certification page is:
"In this course, we offer a brief overview of AWS Secrets Manager, highlighting the integration with Amazon Relational Database Service. The video discusses how this service can help manage secrets like OAuth tokens and application API keys, and concludes with a demonstration of how AWS Secrets Manager can generate and automatically rotate your secrets and passwords."
A similar python script that Bridgid used in her training and certification video is:
print "secrets manager test"
#!/usr/bin/python
import MySQLdb
import boto3
import json
#trying to connect to secrets manager
secretmanager = boto3.client('secretsmanager', endpoint_url='https://secretmanager.us-west-2.amazonaws.com')/
secret_id = 'db/test/DevelopmentDB' #this is the secret name within aws-SecretManager
db_user = json.loads(secretmanager.get_secret_value(SecretId=secret_id)['SecretString'])['username']
db_password = json.loads(secretmanager.get_secret_value(SecretId=secret_id)['SecretString'])['password']
db = MySQLdb.connect(host='secrets-manager--demo.abc123.us-east-1.rds.amazonaws.com', #db endpoint
            user=db_user, #db username
            passwd=db_password, #db username password
            db="secretManager") #db name
# you must create a cursor object, it will let you execute all the queries needed
cur = db.cursor()
cur.execute("select * from employee")
# print all the first cell of all the rows
print "Rows from the test database"
for row in cur.fetchall():
    print row[0]  # index 0 equates to the first field in the record
db.close()


There’s many youtube video’s covering AWS Secrets Manager:
https://www.youtube.com/user/AmazonWebServices/search?query=secrets+manager

No comments:

Post a Comment