You can define the timeout value, which restricts the maximum duration of a single invocation of your Lambda functions.
If your timeout value is too short, Lambda might terminate invocations prematurely. On the other side, setting the timeout much higher than the average execution may cause functions to execute for longer upon code malfunction, resulting in higher costs and possibly reaching concurrency limits depending on how such functions are invoked.
import{Code,Function,Runtime}from'@aws-cdk/aws-lambda';exportclassMyStackextendscdk.Stack{constructor(scope:cdk.Construct,id:string,props?:cdk.StackProps){super(scope,id,props);constmyFunction=newFunction(scope,'MyFunction',{code:Code.fromAsset('src/hello/'),handler:'main.handler',runtime:Runtime.PYTHON_3_8,// Change the function timeouttimeout:10,});}}
1 2 3 4 5 6 7 8 910111213141516
{"Resources":{"MyFunction":{"Type":"AWS::Serverless::Function","Properties":{// Required properties"CodeUri":".","Runtime":"python3.8","Handler":"main.handler",// Change the function timeout"Timeout":10}}}}
1 2 3 4 5 6 7 8 91011
Resources:MyFunction:Type:AWS::Serverless::FunctionProperties:# Required propertiesCodeUri:.Runtime:python3.8Handler:main.handler# Change the function timeoutTimeout:10
1 2 3 4 5 6 7 8 910
provider:name:aws# Change the timeout across all functionstimeout:10functions:hello:handler:handler.hello# Change the timeout for one functiontimeout:15
123456789
resource"aws_lambda_function""this"{function_name="my-function"runtime="python3.8"handler="main.handler"filename="function.zip" # Change the function timeouttimeout=10}