Reputation: 34597
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?
Upvotes: 4
Views: 2450
Reputation: 101
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.
Upvotes: 0
Reputation: 502
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.
Upvotes: 1
Reputation: 2554
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.
Upvotes: 4
Reputation: 697
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)
Upvotes: 0