首页 > 解决方案 > 使用 AWS SAM 的 AWS Lambda 函数在 3 秒后超时

问题描述

我是 AWS 和 Go 的新手,我正在尝试通过 AWS SAM CLI 执行我的 Lambda 函数。但是每次我尝试这样做时,都会出现以下错误:

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:

我不想复制我在 HTTP 请求中传递的信息,因为它很敏感。

知道如何修改这个 3 秒超时吗?

标签: amazon-web-servicesgoaws-lambdaaws-sam-cli

解决方案


Lambda 函数的默认超时时间为 3 秒。您可以通过更新SAM 模板中的Timeout属性来设置任何值,例如

ExampleLambda:
  Type: AWS::Serverless::Function
  Properties:
    CodeUri: .
    Handler: index.handler
    Runtime: nodejs10.x
    Timeout: 10

推荐阅读