0

I am creating a new AWS bot that has to connect to an application installed on my local machine in Apache Tomcat Server. I am able to make a request from postman using the URL 'https://localhost:8080/iii'. But if i give the same URL in my lambda code using python 3.7 and requests function, it is throwing the below error:

[ERROR] ConnectionError: ('Connection aborted.', OSError(97, 'Address family not supported by protocol'))

The logs are:

Traceback (most recent call last):
     File "/var/task/lambda_function.py", line 64, in lambda_handler
    request_status = request_ent(idenName_input,AppName_input,EntName_input,OpName_input)
  File "/var/task/lambda_function.py", line 47, in request_entitlement
    r = requests.post(url, json.dumps(data),auth=('username', 'password'))
  File "/var/runtime/botocore/vendored/requests/api.py", line 109, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/var/runtime/botocore/vendored/requests/api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/var/runtime/botocore/vendored/requests/sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "/var/runtime/botocore/vendored/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/var/runtime/botocore/vendored/requests/adapters.py", line 415, in send
    raise ConnectionError(err, request=request)
END RequestId: 0c190f74-9cd0-49f7-bb6c-be0a98805e83

1 Answers1

0

Localhost as the name suggests is local to your host. It cannot be directly accessed via the internet. To achieve what you are trying, you need to use something like ngrok. It will expose your local apache server on the internet and gives you a public URL where you can send requests and ngrok will forward it to your local apache server.Now, in your lambda function use this ngrok public url and it should work.

But make sure that the Lambda function can access the internet. You need to configure a NAT Gateway and everything. Just read my answer here on how to do this.

Akshay Shah
  • 704
  • 4
  • 11
  • Thanks RayClank. We are planning to do integration between LEX and application in my company. The application is within VPN and the url is not accessible outside of VPN. In that case, if I can connect to aws lex within VPN, Can I establish direct connection from LEX to the application or will I need to make any configuration changes? Any inputs here please. – user1025720 Jun 13 '19 at 18:15
  • I am not sure I completely follow. If there exist a VPN connection between your local machine and application, let's say after the VPN is connected it is accessible at https://localhost:8080 then as mentioned in the answer you can use ngrok for your development and ngrok will forward packets destined to it's public url to the localhost:8080 on your local machine – Akshay Shah Jun 14 '19 at 10:35