How could I retrieve AWS Lambda public IP address by using Python?

I would suggest:

from botocore.vendored import requests
requests.get('http://checkip.amazonaws.com').text.rstrip()

inside your lambda function.

Otherwise you may get an error that says that lambda cannot find requests unless you created your lambda from a .zip file that includes requests installed via pip


You can curl to checkip.amazonaws.com to get the public IP.

import requests
requests.get('http://checkip.amazonaws.com').text.rstrip()

Output:

52.x.147.64