I am trying to execute request.get( ) method for few web urls. And the code is executing perfectly in my local system pycharm, jupyter notebook, google colab notebook etc. Only when I am executing the code in AWS Lambda function, it's working for few urls and throwing timeout exception for other urls. the list of urls are:
- 'https://www.google.com/'
- 'https://stackoverflow.com/'
- 'https://www.nseindia.com/'
- 'https://www.makemytrip.com/'
The code I've developed is
import json
import requests
def lambda_handler(event, context):
url1 = 'https://www.google.com/'
url2 = 'https://stackoverflow.com/'
url3 = 'https://www.nseindia.com/'
url4 = 'https://www.makemytrip.com/'
header = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'
}
response = requests.get(url=url3, headers=header,allow_redirects=False,timeout=60)
for i in response.cookies:
print(i.name +"==>>", i.value)
return
The code is working for url1 and url2 but not working for url3 and url4 in AWS Lambda python shell only, but all the urls are working in google colab or jupyter notebook.