Python requests in AWS Lambda cannot connect to site for proxies

I have an AWS Lambda feature that needs to connect to the internal website that is behind the proxy server. In my code, I do the following:

from botocore.vendored import requests

https_proxy = "https://myproxy:myport"
proxyDict = { 
          "https" : https_proxy
    }
request.get("https://myurl.json", proxies=proxyDict)

Running this causes the following error message:

HTTPSConnectionPool (host = 'myproxyhost', port = 443): Maximum number of attempts exceeded with url: myurl.json (caused by ProxyError ('Cannot connect to proxy.', Gaierror (-2, 'Name or service unknown')))

I tried replacing the proxy address with google.com to confirm that I can connect to other sites (without a proxy).

It looks like the address space that Lambda launches is blocked by the proxy.

Is there anything else I need to ask with queries and lambda to make this work?

+6
3

https_proxy -. - - .

+1

security groups subnets. , . ...

+1

EDIT: , (-2, 'Name or service not known'). Route53 VPC, - , VPC DNS.

, - -, . :

  • , - 443 -
  • -, :

script :

#!/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

.

,

+1

All Articles