如何将 DNS 服务器和网络接口设置为 boto3?
How to set DNS server and network interface to boto3?
我想使用 boto3 将文件上传到 S3。
该代码将 运行 在未配置 DNS 的服务器上运行,我希望上传过程将通过特定的网络接口进行路由。
知道是否有解决这些问题的方法吗?
1) 将 s3 的终点地址添加到 /etc/hosts,参见此列表 http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
2) 配置到网络接口的特定路由,在超级用户上查看此信息
https://superuser.com/questions/181882/force-an-application-to-use-a-specific-network-interface
至于设置网络接口,我做了一个解决方法,允许为 boto 建立的每个连接设置源 ip。
只需将 awsrequest.py AWSHTTPConnection class 更改为以下内容:
a) 在 AWSHTTPConnection 的 init() 之前添加:
source_address = None
b) 在 init() 中添加:
if AWSHTTPConnection.source_address is not None:
kwargs["source_address"] = AWSHTTPConnection.source_address
现在,在您开始使用 boto 之前,您应该根据您的代码执行以下操作:
from botocore.awsrequest import AWSHTTPConnection
AWSHTTPConnection.source_address = (source_ip_str, source_port)
使用 source_port = 0 让 OS 选择随机端口(您可能需要此选项,请参阅 python 套接字文档以获取更多详细信息)
我想使用 boto3 将文件上传到 S3。 该代码将 运行 在未配置 DNS 的服务器上运行,我希望上传过程将通过特定的网络接口进行路由。
知道是否有解决这些问题的方法吗?
1) 将 s3 的终点地址添加到 /etc/hosts,参见此列表 http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
2) 配置到网络接口的特定路由,在超级用户上查看此信息 https://superuser.com/questions/181882/force-an-application-to-use-a-specific-network-interface
至于设置网络接口,我做了一个解决方法,允许为 boto 建立的每个连接设置源 ip。
只需将 awsrequest.py AWSHTTPConnection class 更改为以下内容:
a) 在 AWSHTTPConnection 的 init() 之前添加:
source_address = None
b) 在 init() 中添加:
if AWSHTTPConnection.source_address is not None:
kwargs["source_address"] = AWSHTTPConnection.source_address
现在,在您开始使用 boto 之前,您应该根据您的代码执行以下操作:
from botocore.awsrequest import AWSHTTPConnection
AWSHTTPConnection.source_address = (source_ip_str, source_port)
使用 source_port = 0 让 OS 选择随机端口(您可能需要此选项,请参阅 python 套接字文档以获取更多详细信息)