marcin2x4
marcin2x4

Reputation: 1449

Inject RDS secrets to Python in Lambda

I need to transfer SQL Server RDS' secrets into my Python code that will be ran by Lambda.

What would be best approach to handle such transfer? Sholud it be done with boto3 or/with AWS' Secrets Manager?

Sample Python code:

import pyodbc 

def lambda_handler(event,context):
    conn = pyodbc.connect('Driver={SQL Server};'
                          'Server=server_name;'
                          'Database=db_name;'
                          'Trusted_Connection=yes;')

    cursor = conn.cursor()
    cursor.execute('SELECT * FROM db_name.Table')

    for row in cursor:
        print(row)

Upvotes: 0

Views: 691

Answers (1)

Coin Graham
Coin Graham

Reputation: 1584

This is a great walkthrough with code examples and more importantly, shows how to setup the exceptions in Python for boto3 and SecretsManager.

https://aws.amazon.com/blogs/security/how-to-securely-provide-database-credentials-to-lambda-functions-by-using-aws-secrets-manager/

Upvotes: 1

Related Questions