Wil*_*oss 6 python proxy amazon-web-services aws-lambda
我有一个AWS Lambda函数,需要连接到代理服务器后面的内部网站.在我的代码中,我正在做以下事情:
from botocore.vendored import requests
https_proxy = "https://myproxy:myport"
proxyDict = {
"https" : https_proxy
}
request.get("https://myurl.json", proxies=proxyDict)
Run Code Online (Sandbox Code Playgroud)
运行它给我以下错误消息:
HTTPSConnectionPool(host ='myproxyhost',port = 443):url:myurl.json超出了最大重试次数(由ProxyError引起('无法连接到代理.',gaierror(-2,'名称或服务未知')))
我尝试用google.com替换代理网址,以确认我可以连接到其他网站(没有代理).
看起来Lambda运行它的地址空间被代理阻止.
还有什么我需要设置请求和lambda来使这个工作?
编辑:再次阅读问题后,我意识到错误是由于名称解析造成的(-2, 'Name or service not known')。如果您在 VPC 中使用内部 Route53,下面的解决方案应该仍然有效,因为 lambda 函数将使用 VPC 的 DNS 服务器。
lambda 函数似乎没有在代理实例的同一子网上运行,或者安全组正在阻止连接。要解决这个问题:
这个脚本应该做到这一点:
#!/bin/bash
# Fill the variables bellow with your vpc and subnet id
VPC_ID=""
SUBNET_IDS=""
FUNCTION_NAME=""
SEC_GROUP=$(aws ec2 create-security-group --group-name 'lambda-proxy' --vpc-id $VPC_ID --description 'Lambda/proxy communication' --output text)
aws ec2 authorize-security-group-ingress --group-id ${SEC_GROUP} --protocol tcp --port 443
aws lambda update-function-configuration --function-name $FUNCTION_NAME --vpc-config SubnetIds=$SUBNET_IDS,SecurityGroupIds=$SEC_GROUP
Run Code Online (Sandbox Code Playgroud)
然后将创建的安全组分配给您的实例。
希望能帮助到你
| 归档时间: |
|
| 查看次数: |
2072 次 |
| 最近记录: |