使用AWS SAM,AWS Lambda函数在3秒后超时。

36

我是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秒的超时时间吗?


2
你是如何设置Lambda的?通过控制台?SDK?Cloudformation?对于以上所有方法,您都可以设置超时时间。默认值为3秒,因此会出现上述错误。编辑:啊,您正在使用SAM cli吗?您的项目中可能有一个template.yaml文件。搜索“Timeout”并检查其值。 - Hieron
3个回答

53
Lambda函数的默认超时时间为3秒。您可以通过更新SAM模板中的Timeout属性设置任何值,例如: Timeout
ExampleLambda:
  Type: AWS::Serverless::Function
  Properties:
    CodeUri: .
    Handler: index.handler
    Runtime: nodejs10.x
    Timeout: 10

20

我使用template.yml来设置我的Lambda。当我引入Timeout属性时,我忘记重新构建和运行sam local start-api。这是一个诚实的错误,请谢谢您的时间。


3

这与 sam local start-api 无关,但如果您在 PyCharm 中开发并使用运行按钮运行单个 Lambda 函数,则还有另一个设置可能会被忽视。您可以在运行配置窗口中找到它,用于指定超时时间:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接