0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[メモ]AWS-AmplifyでのAPIGatewayタイムアウト関連

Posted at

AmplifyGen2でもろもろ開発しているのですが、APIGateway-Lambda統合でのタイムアウト時の動作がちゃんと頭に入っていなかったので、詳しく調べてみました。(2025-11-08)

この記事ではAppSyncは検証していません。

デフォルト値

APIGatewayのデフォルトタイムアウトは29秒
Lambdaでのデフォルトタイムアウトは3秒
Amplifyにしてもいっしょ。

最大値

APIGatewayの29秒デフォルト値は、最大値である。
APIGatewayのタイムアウト最大値はサポートへリクエストすることで拡大できるらしい(未検証)
Lambdaのタイムアウトは最大900秒(15分)

動作

実際の動作を調べてみました。

ケース1

  • API=29s
  • Lambda=10s
  • 実行wait=5s

通常に動作して、レスポンスが返ってきました。

ケース2

  • API=29s
  • Lambda=3s
  • 実行wait=5s

Lambdaの実行時間がLambdaのタイムアウトを超える場合。
APIGatewayからは500:internalで返る(デフォルト設定)

ケース3

  • API=29s
  • Lambda=10s
  • 実行wait=5s
  • 人為的にコネクションを切断した場合

最後まで実行される。Lambdaの完結はAPIGatewayの状態は関係がないようだ。

ケース4

  • API=29s
  • Lambda=60s
  • 実行wait=45s

Lambdaの実行時間が、APIGatewayのタイムアウトを超えた場合。
Lambdaの実行はAPIGatewayのタイムアウトが起こっても、最後まで実行される。
{ "message" : "Endpoint request timed out" } : 504 error

ケース5

  • Lambda=901s

デプロイできない

ケース6

  • APIGateway=30s

デプロイできない

タイムアウトの設定方法

amplifyでの設定方法メモ。

Lambdaのタイムアウトの設定方法

import { defineFunction } from '@aws-amplify/backend-function';

export const anyFunction = defineFunction({
  name: 'any-fnc',
  entry: './any-fnc.ts',
  environment: {
    ENVIRONMENT: 'test',
  },
  // Nodeランタイム
  runtime: 20,

  // ここがLambda単独のタイムアウト設定
  timeoutSeconds: 900, //15min
  
  //1日ごとに実行(EventBridge式)
  schedule: `0 15 * * ? *`
});

APIGatewayのタイムアウト設定方法

現状デフォルトでMAX(29s)なので、使っても意味はない。

const integration = new LambdaIntegration(backend.anyFunction.resources.lambda, {
  timeout: Duration.seconds(15), 
});

まとめ

APIGatewayはタイムアウトを触らなくてもよい。
LambdaはAPIGatewayの時間を超えて実行させられる。
Lambdaの処理完結は、コネクションやAPIGatewayのタイムアウトとは関係がない。


この記事は以上です。ありがとうございました。

kintoneのプラグイン開発や研修などを行っています。
お仕事のお話はこちらまで。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?