0

I am trying send a POST request from AWS python lambda function but getting following error while sending:

[ERROR] ConnectionError: HTTPConnectionPool(host= ********************s3-website.ap-south-1.amazonaws.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f69fdfbda90>: Failed to establish a new connection: [Errno 110] Connection timed out')) Traceback (most recent call last):

![Response]

I tried with the following code:

import json
import uuid
import datetime
import re
import base64
import requests
import httpx
import asyncio
def lambda_handler(event,context):

    INVENTORY_CP_OPERATION_URL="************.s3-website.ap-south- 
                 1.amazonaws.com/"
    message={
       "email":"*******@********.com",
       "password":"123456"
        }
    result=requests.post(**************,json=message)
    return "success".
3
  • Is your AWS Lambda function connected to a VPC? If so, is there a particular reason for doing so? If not, disconnect the Lambda function from the VPC and try again. Let us know what happens. Commented Jul 19, 2022 at 7:18
  • Yes sir, by disconnecting the VPC, its working fine. Commented Jul 19, 2022 at 7:36
  • Does that solve your issue? Commented Jul 19, 2022 at 7:46

1 Answer 1

2

Given your Connection timed out, it would seem that your AWS Lambda function is having difficulty connecting to the Internet.

When an AWS Lambda function is NOT connected to a VPC, it has direct access to the Internet.

However, when a Lambda function IS connected to a VPC, it only has Internet access if the Lambda function is connected to a private subnet and there is a NAT Gateway in a public subnet.

Therefore, if the function does not require access to any resources in a VPC (eg Amazon RDS databases), then it is best to disconnect it from the VPC.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, we are connecting VPC to the subnets still not getting internet access.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.