Task timed out after 6.00 seconds エラーの解決方法 [Serverless Framework][AWS Lambda]

Serverless Framework で AWS Lambda へ deploy した function が Task timed out after 6.00 seconds エラーを発生したときの解決方法をご紹介します。

Serverless Framework

(前提) AWS Lambda デフォルトタイムアウトは 6 秒

公式ドキュメントとフォーラムによると、AWS Lambda の default timeout は 6 秒のようでした。

# serverless.yml
provider:
  timeout: 10 # The default is 6 seconds. Note: API Gateway current maximum is 30 seconds

functions:
  usersCreate: # A Function
    timeout: 10 # Timeout for this specific function.  Overrides the default set above.

Task timed out after 6.00 seconds の解決方法

The default is 6 seconds. なので、今回タイムアウトした function の timeout 設定値を 60秒に延ばして対応しました。

diff --git a/serverless.yml b/serverless.yml
index 789903d..08183dc 100644
--- a/serverless.yml
+++ b/serverless.yml
@@ -57,6 +57,7 @@ provider:
 functions:
   hello:
     handler: handler.hello
+    timeout: 60 # The default is 6 seconds. Note: API Gateway current maximum is 30 seconds
 
 #    The following are a few example events you can configure
 #    NOTE: Please make sure to change your handler code to work with those events

以上、Task timed out after 6.00 seconds エラーを解決した現場からお送りしました。