Monday 21 August 2023

Why does AWS Lambda experience a consistent 10-second delay for an unresolvable domain using requests.get?

I'm experiencing a peculiar behavior when trying to make an HTTP request to unresolved domain names from an AWS Lambda function using the requests library in Python.

When I attempt to make a request using:

response = requests.get('https://benandjerry.com', timeout=(1,1))

In AWS Lambda, it consistently takes around 10 seconds before it throws an error. However, when I run the same code on my local environment, it's instant. I've verified this using logs and isolated tests.

I've considered potential issues like Lambda's cold starts, Lambda runtime differences, and even VPC configurations, but none seem to be the root cause.

I also tried using curl to access the domain, and it instantly returned with Could not resolve host: benandjerry.com.

Last point, this is happening on specific unresolved domain names, not all of them, and if I use urllib.request instead of requests, it works.

Here's a sample:

Questions:

  1. What could be causing this consistent 10-second delay in AWS Lambda for an unresolvable domain using requests?
  2. How can I get AWS Lambda to instantly recognize that the domain is unresolvable, similar to the behavior on my local machine?


from Why does AWS Lambda experience a consistent 10-second delay for an unresolvable domain using requests.get?

No comments:

Post a Comment