问题
I am going through AWS boto3 rds documentation for running sql select query on table which is present in RDS SQL Server using python in AWS lambda, but I didn't find any info. Don't we have any option to run RDS SQL queries in AWS lambda? Any ideas!
rds_client = boto3.client('rds')
回答1:
boto3 library provides API to communicate with AWS API. The AWS RDS API includes of
- Listing all RDS Instances
- Create new RDS Instances
- Stop RDS Instances
- Modify RDS Instances
- etc
For Lambda or any programming language to communicate with database server, we first need to install database driver. Think of it as a middle-man (drivers) that collect instructions of programming language, convert it to database understandable language, then database to process it and return the information to the middle-man, and middle-man translate it to something your programming language can understand. Boto3 does not come with any relational database drivers.
To allow Lambda to work your RDS SQL Server, you have to install Python's SQL Server driver and upload to Lambda. You can either package it as a standalone zip or make it as a Lambda Layer that can be used across by multiple Lambda Functions. The commonly used SQL Server driver for python is pyodbc
Someone on medium.com have make a blogpost about this.
来源:https://stackoverflow.com/questions/65663732/how-to-run-rds-sql-server-select-queries-in-aws-lambda-using-boto3-rds-client-py