Reputation: 91
I'm pretty new to AWS Lambda functions.
I'm trying to get a .xlsx
file from a website and put it on a private Amazon S3 bucket.
The following code leads to a timeout when running the put_object
function and I don't know how doing now ... What am I doing wrong? I'm so close...
This code works on our backend to write to a file.
import json
import boto3
from botocore.vendored import requests
import json
s3 = boto3.client('s3')
def lambda_handler(event, context):
url = "https://some_url"
path = "first_folder_in_my_private_bucket/subfolder/subsubfolder/subsubsubfolder/"
key = f"{path}test.xlsx"
headers = {
"User-Agent": "Mozilla/5.0",
"Connexion": "keep-alive",
"Accept-Encoding": "gzip, deflate, br"}
body = {
"login": "our_website_login",
"password": "our_website_password"}
login = requests.post(url=f"{url}index.php", data=body)
if login.status_code == 200:
response = requests.get(
url=f"{url}export_excel.php",
allow_redirects=True,
headers=headers,
cookies=login.cookies)
# Here response.content have the good payload, and we reach this point
s3.put_object(Bucket="maprochaineauto-s3", Key=key, Body=response.content)
# We never reach this point and the error response is next this code sample
return {"response":"Worked"}
return {"response":"Not worked"}
Test Event Name
test
Response
{
"errorMessage": "blablatimestamp blablacode Task timed out after 3.00 seconds"
}
Function Logs
START RequestId: blablaId Version: $LATEST
/opt/python/botocore/vendored/requests/api.py:65: DeprecationWarning: You are using the post() function from 'botocore.vendored.requests'. This is not a public API in botocore and will be removed in the future. Additionally, this version of requests is out of date. We recommend you install the requests package, 'import requests' directly, and use the requests.post() function instead.
warnings.warn(
/opt/python/botocore/vendored/requests/api.py:65: DeprecationWarning: You are using the get() function from 'botocore.vendored.requests'. This is not a public API in botocore and will be removed in the future. Additionally, this version of requests is out of date. We recommend you install the requests package, 'import requests' directly, and use the requests.get() function instead.
warnings.warn(
END RequestId: Blabla ID
REPORT RequestId: BlablaID Duration: 3003.50 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 75 MB Init Duration: 571.68 ms
2021-06-14T08:41:22.413Z BlablaID Task timed out after 3.00 seconds
Request ID
BlablaID
I installed a layer to normally prevent the requests warnings but it's not really working, as you see.
I don't have permissions to see role permissions on the lambda, but "normally" it's a god-like lambda function with a lot of permissions.
Upvotes: 1
Views: 755
Reputation: 238507
Based on the comments.
The issue was caused by a default lambda timeout of 3 seconds. Increasing the timeout in AWS console was the solution to the problem reported.
Upvotes: 1