Send payload:
{
"request": "<url>"
}
The lambda will request the address and return the output in it's logs.
| import requests | |
| def handler(event,context): | |
| print("Requesting {}".format(event["request"])) | |
| try: | |
| res = requests.get(event["request"], timeout = 10) | |
| except requests.ConnectionError as ex: | |
| print("A connection error occurred") | |
| print(ex) | |
| exit(1) | |
| except requests.exceptions.RequestException as ex: | |
| print("A generic request library error occurred") | |
| print(ex) | |
| exit(1) | |
| except Exception as ex: | |
| print("Exception type: {}".format(type(ex).__name__)) | |
| print("An error occurred while contacting the server") | |
| exit(1) | |
| print("Status Code: {} [{}]".format(res.status_code,res.reason)) | |
| if res.ok: | |
| print("Response is okay") | |
| print(res.content) | |
| else: | |
| print("Response is not okay") |
| requests |