要件としては、ApiGateway <=> Lambda の統合設定条件配下にて、 Lambdaからの応答結果が6MBを超えた場合に以下のようなログが出力される
Lambda execution failed with status 200 due to customer function error: body size is too long. Lambda request id: XXXX-XXXX...
これに対して、ServerlessFramework でログ設定を行いたい
参考
- Serverless.yml Reference
- Enhancements for API Gateway REST API log setup
- Serverless complains about “Rest API id could not be resolved.”
ApiGateway ステージ ログ/トレース の設定と動作
IAM Policy作成含め以下の設定だけで作成される
provider:
logs:
restApi:
accessLogging: false # Optional configuration which enables or disables access logging. Defaults to true.
executionLogging: true # Optional configuration which enables or disables execution logging. Defaults to true.
level: ERROR # Optional configuration which specifies the log level to use for execution logging. May be set to either INFO or ERROR.
fullExecutionData: false # Optional configuration which specifies whether or not to log full requests/responses for execution logging. Defaults to true.
CloudWatch ログを有効化(INFO/ERROR等の選択)
API-Gateway-Execution-Logs_[APIID]/[stage] という形式でロググループが作成される
- ここに
body size too long
のログがでる
- ここに
ERROR のみで指定しないとリクエストが多い場合すぐ埋もれる。。
リクエスト/レスポンスをすべてログ
- /aws/api-gateway/[serviceName]-[stage] ロググループ
アクセスカスタムログ
- /aws/api-gateway/[serviceName]-[stage] ロググループ
format:
で指定できる