简体   繁体   English

从AWS Lambda使用Windows Auth调用MSSQL

[英]Call MSSQL with Windows Auth from AWS Lambda

Is it possible to call MSSQL from AWS Lambda when MSSQL is part of windows domain and only allows windows authentication? 当MSSQL是Windows域的一部分并且仅允许Windows身份验证时,是否可以从AWS Lambda调用MSSQL? Eg Is there any way to run Lambda function under AD user? 例如,有什么方法可以在AD用户下运行Lambda函数? or use AD connector to associate AD user with IAM account and run Lambda under that account? 或使用AD连接器将AD用户与IAM帐户关联并在该帐户下运行Lambda?

Yes, we can use pymssql python module inside the lambda function to connect to mssql server and execute your commands. 是的,我们可以在lambda函数中使用pymssql python模块连接到mssql服务器并执行您的命令。 You need to zip the pymssql module as a lambda deployment package. 您需要将pymssql模块压缩为lambda部署程序包。 here is the example of command and connection: 这是命令和连接的示例:

import boto3
import pymssql
#setup connection
conn = pymssql.connect("serverurl", "username", "password", "dbname")
#setup cursor, so that you can use it to execute your commands
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE persons (
    id INT NOT NULL,
    name VARCHAR(100),
    salesrep VARCHAR(100),
    PRIMARY KEY(id)""")
# you must call commit() to persist your data if you don't set autocommit to True
conn.commit()

But, to connect using Windows Authentication, here is some mods: When connecting using Windows Authentication, this is how to combine the database's hostname and instance name, and the Active Directory/Windows Domain name and the username. 但是,要使用Windows身份验证进行连接,请使用以下模块:当使用Windows身份验证进行连接时,这是将数据库的主机名和实例名以及Active Directory / Windows域名和用户名结合在一起的方法。

conn = pymssql.connect(
    host=r'dbhostname\myinstance',
    user=r'companydomain\username',
    password=PASSWORD,
    database='DatabaseOfInterest'
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM