简体   繁体   English

使用Python 3 AWS Lambda函数连接到OpenVPN服务器

[英]Connect to OpenVPN server in Python 3 AWS Lambda Function

I need to be able to connect to an OpenVPN server using a .ovpn file within a Python 3 script. 我需要能够使用Python 3脚本中的.ovpn文件连接到OpenVPN服务器。 Right now my script runs just fine, as the machine I'm running it on is connected to the OpenVPN server using Tunnelblick. 现在,我的脚本运行得很好,因为我正在运行脚本的计算机已使用Tunnelblick连接到OpenVPN服务器。

The goal is to have this run in an AWS Lambda function. 目标是使它在AWS Lambda函数中运行。 So as part of the execution it would use the ovpn cert to connect the vpn, do it's thing, then disconnect. 因此,作为执行的一部分,它将使用ovpn证书连接vpn,执行此操作,然后断开连接。

Maybe I'm just looking for a module that functions as an OpenVPN Client? 也许我只是在寻找一个充当OpenVPN客户端的模块? I'm currently using the paramiko module to ssh into a Linux box also connected to the OpenVPN server. 我目前正在使用paramiko模块将ssh放入一个Linux盒子中,该盒子也已连接到OpenVPN服务器。

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(remote_ip, username='username', password=password)
stdin, stdout, stderr = ssh.exec_command(diagnose_script)
stdin.flush()
data = stdout.read().splitlines()
results = ''
for line in data:
    results += line.decode('utf-8')
    results += '\n'
return results
ssh.close()

If you have hundreds/thousands of boxes to connect to - AWS VPC (Virtual Private Cloud) sounds like a proper solution for your problem. 如果您有成百上千个要连接的盒子-AWS VPC(虚拟私有云)听起来像是解决问题的合适方法。 It might a bit more effort and cost, but it's sustainable in the long term and I would say more secure. 这可能会花费更多的精力和成本,但从长远来看是可持续的,我会说更加安全。

There are multitude of options to choose from, and in your case AWS Managed VPN or Software VPN would fit best. 很多选项可供选择,对于您而言, AWS Managed VPNSoftware VPN最为合适。 Then you can have your Lambdas and outside AWS resources to run in one network. 然后,您可以让Lambda和外部AWS资源在一个网络中运行。

Connecting to an OpenVPN from AWS Lambda is possible, you can install any packages you want, since it's a Linux container and I'm pretty sure there are some answers here about it, albeit it will cost you quite a bit of execution time especially if the function won't be called in a high volume (at least once per minute or so), since the container will have to start up and all the packages to be setup again. 可以从AWS Lambda连接到OpenVPN,您可以安装任何所需的软件包,因为它是Linux容器,并且我敢肯定这里有一些答案,尽管这样做会花费您很多执行时间,尤其是在不会大量调用该函数(至少每分钟一次),因为容器必须启动并且所有软件包都必须重新设置。

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

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