我的应用程序是使用链接(url)来调用lambda函数,然后我想知道lambda的公共IP并获取页面源。我如何通过使用python获取lambda公共IP?非常感谢。
你可以卷曲到checkip.amazonaws.com
获得公共IP。
import requests
requests.get('http://checkip.amazonaws.com').text.rstrip()
输出:
52.x.147.64
我会建议:
from botocore.vendored import requests
requests.get('http://checkip.amazonaws.com').text.rstrip()
在你的lambda
功能内。
否则,您可能会收到一条错误消息,指出lambda无法找到requests
,除非您从.zip文件创建了lambda,该文件包含通过requests
安装的pip