Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Cast header Lambda-Runtime-Deadline-Ms to int for Python2.7/3.6 runtimes #224

Closed
wants to merge 1 commit into from
Closed

Conversation

jhaenchen
Copy link

We are experiencing an issue with 2.7 runtime when calling get_remaining_time_in_millis. It appears that in the runtime the variable DEADLINE_MS is overwritten with a value pulled directly from a header, which is a string. Then when get_remaining_time_in_millis is called, it tries to subtract an int from a string, and so throws. This PR simply casts the received header value to an int before overwriting the variable.

Proof of bug:

"""
Save this to a file named lambda_function.py
 
Runs without problem in python 3.7
docker run --rm -v $PWD:/var/task lambci/lambda:python3.7 lambda_function.lambda_handler
 
Has problems in python 2.7 and 3.6
docker run --rm -v $PWD:/var/task lambci/lambda:python2.7 lambda_function.lambda_handler
docker run --rm -v $PWD:/var/task lambci/lambda:python3.6 lambda_function.lambda_handler
"""
 
def lambda_handler(event, context):
    # https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
    func_name = context.function_name
    rem_time_ms = context.get_remaining_time_in_millis()
 
    return {
        "func_name": func_name,
        "rem_time_ms": rem_time_ms,
    }

@jhaenchen jhaenchen closed this Nov 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant