4

In the documentation of chalice one can see an example of a configuration of a lambda function on aws provisioned by chalice.

The idea is that you can define an app like below:

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'}

And with this app you can set the config.json file like so;

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

When you do this, you set the timeout for the test_lambda function.

I was wondering, is it possible to set the timeout of the index function? The one that does not have the @app.lambda_function() decorator but the one that has the @app.route('/') decorator?

cantdutchthis
  • 31,949
  • 17
  • 74
  • 114
  • 1
    AWS only handles execution time per Lambda function, not per route. If you need a specifc route to have a different timeout limit, I'd suggest to keep it in a separated Lambda function. Otherwise, you'll need to use some tricks to keep track of how long the route function has taken and return to the client when a given threshold is reached... – Renato Byrro Feb 01 '18 at 01:47

4 Answers4

3

Change the config.json file as follow:

 {
  "stages": {
    "dev": {
      "api_gateway_stage": "api"
    }
  },
  "version": "2.0",
  "app_name": "myappname",
  "lambda_memory_size" : 2048,
  "lambda_timeout" : 120
}

No need to use lambda decorator or anything.

john
  • 2,324
  • 3
  • 20
  • 37
1

If the requirements aren't met when it hits the route in Chalice, it will either fail or pass. There is not a timeout setting in Chalice routing.

There is however a timeout setting in Chalice for the lambdas which an be set in the config.

griff4594
  • 484
  • 3
  • 15
0

enter image description here

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: (see above pic)

Down the Stream
  • 639
  • 7
  • 10
0

When you want to set the timeout on a non-pure lambda (not previously declared in the app context), the name of lambda in AWS is prefixed. But, in config file you should not set this prefix.

The correct name of the lambda function for this configuration is in your declared resources file, in the chalice at .chalice/deployed/prod.json

Use the name of the respective lambda function from this file, not from the AWS console.