diff --git a/infrastructure/terraform/modules/lambda_with_api_gateway/main.tf b/infrastructure/terraform/modules/lambda_with_api_gateway/main.tf index b1ee3b75..bef4a16c 100644 --- a/infrastructure/terraform/modules/lambda_with_api_gateway/main.tf +++ b/infrastructure/terraform/modules/lambda_with_api_gateway/main.tf @@ -6,6 +6,14 @@ module "role" { name = "${var.name}-lambda-${var.stage}" } +############################################ +# Cloudwatch log group +############################################ +resource "aws_cloudwatch_log_group" "api_logs" { + name = "/aws/apigateway/${var.name}-${var.stage}" + retention_in_days = 14 +} + ############################################ # Install python packages ############################################ @@ -68,6 +76,19 @@ resource "aws_apigatewayv2_stage" "this" { api_id = aws_apigatewayv2_api.this.id name = "$default" auto_deploy = true + + access_log_settings { + destination_arn = aws_cloudwatch_log_group.api_logs.arn + + format = jsonencode({ + requestId = "$context.requestId" + domainName = "$context.domainName" + path = "$context.path" + status = "$context.status" + sourceIp = "$context.identity.sourceIp" + userAgent = "$context.identity.userAgent" + }) + } } resource "aws_apigatewayv2_integration" "this" {