Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda function Timedout after 3 sec using AWS SAM

I am new to AWS and Go and I am trying to execute my Lambda function via AWS SAM CLI. But every time I try to do so I get the following error:

I0517 07:51:11.052078      13 main.go:62] Thumbnail Lambda successfully started 
I0517 07:51:13.696304      13 utils.go:99] Needed directories successfully created
2019-05-17 09:51:14 Function 'Thumbnail' timed out after 3 seconds
2019-05-17 09:51:14 Function returned an invalid response (must include one of: body, headers or statusCode in the response object). Response received:

I did not want to copy information I pass in the HTTP request since its sensitive.

Any idea how I can modify this 3 second timeout?

like image 327
Stefan Radonjic Avatar asked May 17 '19 08:05

Stefan Radonjic


People also ask

Why is my Lambda function timing out after 3 seconds?

The default timeout of a Lambda function is three seconds. This means, if you don't explicitly configure a timeout, your function invocations will be suspended after three seconds. Now, if you call a few services, some of which are currently at capacity, a request can very well take a second on its own.

How long can an AWS Lambda function execute in seconds?

AWS Lambda functions can be configured to run up to 15 minutes per execution. You can set the timeout to any value between 1 second and 15 minutes.

Does AWS Lambda retry after timeout?

Short description. There are three reasons why retry and timeout issues occur when invoking a Lambda function with an AWS SDK: A remote API is unreachable or takes too long to respond to an API call. The API call doesn't get a response within the socket timeout.


3 Answers

The default timeout of Lambda functions is 3 seconds. You can set any value by updating the Timeout property in your SAM template, e.g.

ExampleLambda:
  Type: AWS::Serverless::Function
  Properties:
    CodeUri: .
    Handler: index.handler
    Runtime: nodejs10.x
    Timeout: 10
like image 189
matsev Avatar answered Oct 10 '22 23:10

matsev


I am using template.yml in order to set up my lambda. I forgot to re-build and re-run sam local start-api when I introduced Timeout property to it. Honest mistake, thank you for your time.

like image 28
Stefan Radonjic Avatar answered Oct 11 '22 00:10

Stefan Radonjic


This doesn't pertain to sam local start-api, but if you're developing in PyCharm and running a single Lambda function with the PyCharm run button, there's another setting you might not have seen in the run configuration window where you can specify the timeout:

enter image description here

like image 3
Tobias Feil Avatar answered Oct 11 '22 01:10

Tobias Feil