I'm new to AWS and Python. I'm trying to get the results of HTTP requests through Lambda. I attached the layer which includes requests library.
Here is the problem:
Runtime:Python 3.7
import requests
# import urllib.request *already tried
# from botocore.vendored import requests *already tried
def lambda_handler(event, context):
params = (
('hoge', 'fuga'),
('piyo', 'pipiyo')
)
print('API start')
response = requests.get('https://sample.com', params=params)
if response is None:
print('no response')
print(response)
# get the first num of status code
status = response.status_code
print(status)
status_head = status[1]
output = response.json()
print(output)
# get the result and error message from body
json_data = json.load(output)
result = json_data["result"]
error = json_data["error"]
print(result)
print(error)
return result
What I get is
Response:
{
"errorMessage": "2020-06-24T05:50:43.309Z 035e9470-c067-40bb-adc3-7c5b1f72f885 Task timed out after 60.06 seconds"
}
Request ID:
"035e9470-c067-40bb-adc3-7c5b1f72f885"
Function Logs:
START RequestId: 035e9470-c067-40bb-adc3-7c5b1f72f885 Version: $LATEST
API start
END RequestId: 035e9470-c067-40bb-adc3-7c5b1f72f885
REPORT RequestId: 035e9470-c067-40bb-adc3-7c5b1f72f885 Duration: 60058.03 ms Billed Duration: 60000 ms Memory Size: 128 MB Max Memory Used: 73 MB Init Duration: 789.24 ms
2020-06-24T05:50:43.309Z 035e9470-c067-40bb-adc3-7c5b1f72f885 Task timed out after 60.06 seconds
When I send this request from Talend API Tester, the response returns right.
Do I have to change parameters of test events? Does that matter? Current content is
{
"key1": "value1",
"key2": "value2"
}
What am I missing here? Please tell me if I have to add more info. Thanks in advance!