Chalice: Configure Pure Lambda Timeout

Created on 29 Aug 2017  路  8Comments  路  Source: aws/chalice

I couldn't find this in the documentation for pure lambdas, but it would be great if we can set the timeout for each pure lambda. Right now, we would need to go into AWS Lambda dashboard to change this after every deployment I believe.

Perhaps something like:

@app.lambda_function(name='MyFunction', timeout=120)

documentation

Most helpful comment

I have tried it today using chalice 1.1.0 and using the below in my config.json. However, when going to aws lambda dashboard for that function, it still says it is 60 seconds for timeout and memory size 128MB. I am not sure if this is a bug or I am doing something wrong. I do not get any errors during the deployment process. @jamesls please re-look into this issue. I cannot get this to work

"lambda_functions": {
"some_function": {
"lambda_timeout": 120,
"lambda_memory_size": 256
}
}

All 8 comments

Looks like we're missing docs on this in our configfile doc page (http://chalice.readthedocs.io/en/latest/topics/configfile.html), but you can configure this in the .chalice/config.json file. For example, if I have a lambda function named test_lambda:

from chalice import Chalice

app = Chalice(app_name='demotimeout')


@app.route('/')
def index():
    return {'hello': 'world'}

@app.lambda_function()
def test_lambda(event, context):
    return {'hello': 'world'}

Then I can add a "lambda_functions" key which is a dictionary of lambda function name to config. So in this case the key should be test_lambda:

{
  "stages": {
    "dev": {
      "api_gateway_stage": "api",
      "lambda_functions": {
        "test_lambda": {
          "lambda_timeout": 120
        }
      }
    }
  },
  "version": "2.0",
  "app_name": "demotimeout"
}

This stackoverflow question may be relevant to this thread too: https://stackoverflow.com/questions/48244839/set-timeout-for-chalice-functions-in-general.

@jamesls That Configuration File docs page does have some documentation for Lambda timeout:

lambda_timeout - An integer representing the function execution time, in seconds, at which AWS Lambda should terminate the function. The default lambda_timeout is 60 seconds.

I have tried it today using chalice 1.1.0 and using the below in my config.json. However, when going to aws lambda dashboard for that function, it still says it is 60 seconds for timeout and memory size 128MB. I am not sure if this is a bug or I am doing something wrong. I do not get any errors during the deployment process. @jamesls please re-look into this issue. I cannot get this to work

"lambda_functions": {
"some_function": {
"lambda_timeout": 120,
"lambda_memory_size": 256
}
}

I'm facing this issue @levanhieu-git. Any update?

No updates yet on it. I am not sure if people are still aware of the problem? We may need to make a new issue ticket? @jjbeber

Here is one way to configure timeout for aws lambda and deploy it:

    $> chalice --version
    chalice 1.2.2

1st create a "pure lambda", refer to this link for details:
http://chalice.readthedocs.io/en/latest/topics/purelambda.html

@app.lambda_function(name='FancyLambdaFunc')
def fancy_handler(event, context):
    # Do all the fancy stuff ...

2nd in config.json add:

    "dev": {
      "api_gateway_stage": "api",
      "lambda_functions": {
    "FancyLambdaFunc": {
      "lambda_timeout": 240
    }
      }
    }

finally verify in AWS:

I've also confirmed this is working for me on the latest chalice version (1.2.3). Here's the exact steps I followed:

$ chalice new-project testtimeout
$ cd testtimeout
$ # Modify app.py to have a single lambda function
$  cat app.py
from chalice import Chalice

app = Chalice(app_name='testtimeout')


@app.lambda_function()
def test_timeout(event, context):
    return {'hello': 'world'}

$ chalice deploy
Creating deployment package.
Creating IAM role: testtimeout-dev
Creating lambda function: testtimeout-dev-test_timeout
Resources deployed:
  - Lambda ARN: arn:aws:lambda:us-west-2:12345:function:testtimeout-dev-test_timeout

$ aws lambda get-function-configuration --function-name arn:aws:lambda:us-west-2:12345:function:testtimeout-dev-test_timeout
{
    "FunctionName": "testtimeout-dev-test_timeout",
    "LastModified": "2018-05-17T15:37:05.501+0000",
    "RevisionId": "55d742ac-44fe-43e5-9b9b-113c9ad2f95f",
    "MemorySize": 128,
    "Environment": {
        "Variables": {}
    },
    "Version": "$LATEST",
    "Role": "arn:aws:iam::12345:role/testtimeout-dev",
    "Timeout": 120,
    "Runtime": "python2.7",
    "TracingConfig": {
        "Mode": "PassThrough"
    },
    "CodeSha256": "BjXRSYksnqkRmCSL/pQALi+UZmqOnOOzH3g1nmHL6MI=",
    "Description": "",
    "CodeSize": 9134,
    "FunctionArn": "arn:aws:lambda:us-west-2:12345:function:testtimeout-dev-test_timeout",
    "Handler": "app.test_timeout"
}

We've also updated the docs for this (http://chalice.readthedocs.io/en/latest/topics/configfile.html). If you're still running into issues on the latest version, let me know and I'll take another look.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Erstwild picture Erstwild  路  4Comments

adsahay picture adsahay  路  4Comments

michaeldimchuk picture michaeldimchuk  路  3Comments

GDavisSS picture GDavisSS  路  3Comments

AtaruOhto picture AtaruOhto  路  3Comments