1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] AWS Lambda timing out on return statement

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to write a simple lambda function to use as a view for an application that has parquet data living in an S3 bucket. I'm just trying to test out a simple function here:

    import json
    import time
    t = time.time()
    print('This ')

    import os
    import urllib.parse
    import boto3
    import pandas as pd
    import awswrangler as wr

    print('Imports complete: ', time.time() - t)


    s3 = boto3.client('s3')

    def lambda_handler(event, context):
    bucket = os.environ['S3_BUCKET']
    try:
    print('wrangling df')
    df = wr.s3.read_parquet(bucket, dataset=True)
    print('df loaded: ',time.time() - t)
    response = df.to_json()
    print('response type: ', type(response))
    print('df to json: ',time.time() - t)
    return response
    except Exception as e:
    print('exception caught: ',time.time() - t)
    print(e)
    print('Error getting object from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(bucket))
    raise e


    I'm using the managed python layer on us-west-2:

    arn:aws:lambda:eu-west-2:336392948345:layer:AWSSDKPandas-Python312:13


    This is the output with a 60s timeout configured:

    Test Event Name
    (unsaved) test event

    Response
    {
    "errorType": "Sandbox.Timedout",
    "errorMessage": "RequestId: 24b0f94f-a78e-40e4-9573-0e49ac3eeef3 Error: Task timed out after 60.00 seconds"
    }

    Function Logs
    This
    Imports complete: 4.597054481506348
    START RequestId: 24b0f94f-a78e-40e4-9573-0e49ac3eeef3 Version: $LATEST
    wrangling df
    df loaded: 10.094886779785156
    response type: <class 'str'>
    df to json: 10.67463231086731
    END RequestId: 24b0f94f-a78e-40e4-9573-0e49ac3eeef3
    REPORT RequestId: 24b0f94f-a78e-40e4-9573-0e49ac3eeef3 Duration: 60000.00 ms Billed Duration: 60000 ms Memory Size: 128 MB Max Memory Used: 126 MB Init Duration: 4874.63 ms Status: timeout

    Request ID
    24b0f94f-a78e-40e4-9573-0e49ac3


    So it looks like the function is just hanging at the return statement when I test it. Oddly if I replace return response with return 'some text' it returns right after finishing. Why would a string several kbs long change the return time by 50+ s?

    Continue reading...

Compartilhe esta Página