|
| 1 | +resource "aws_api_gateway_stage" "main" { |
| 2 | + stage_name = "main" # This is the default stage name for API Gateway |
| 3 | + description = "Templates API stage ${var.environment}" |
| 4 | + rest_api_id = aws_api_gateway_rest_api.main.id |
| 5 | + deployment_id = aws_api_gateway_deployment.main.id |
| 6 | + |
| 7 | + access_log_settings { |
| 8 | + destination_arn = aws_cloudwatch_log_group.api_gateway_access.arn |
| 9 | + |
| 10 | + # Context variables reference - https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference |
| 11 | + format = jsonencode({ |
| 12 | + "accountId" : "$context.accountId" |
| 13 | + "apiId" : "$context.apiId" |
| 14 | + "authorize" : { |
| 15 | + "error" : "$context.authorize.error" |
| 16 | + "latency" : "$context.authorize.latency" |
| 17 | + "status" : "$context.authorize.status" |
| 18 | + } |
| 19 | + "authorizer" : { |
| 20 | + "error" : "$context.authorizer.error" |
| 21 | + "integrationLatency" : "$context.authorizer.integrationLatency" |
| 22 | + "integrationStatus" : "$context.authorizer.integrationStatus" |
| 23 | + "latency" : "$context.authorizer.latency" |
| 24 | + "principalId" : "$context.authorizer.principalId" |
| 25 | + "requestId" : "$context.authorizer.requestId" |
| 26 | + "status" : "$context.authorizer.status" |
| 27 | + } |
| 28 | + "awsEndpointRequestId" : "$context.awsEndpointRequestId" |
| 29 | + "deploymentId" : "$context.deploymentId" |
| 30 | + "domainName" : "$context.domainName" |
| 31 | + "domainPrefix" : "$context.domainPrefix" |
| 32 | + "endpointType" : "$context.endpointType" |
| 33 | + "error" : { |
| 34 | + "message" : "$context.error.message" |
| 35 | + "responseType" : "$context.error.responseType" |
| 36 | + "validationErrorString" : "$context.error.validationErrorString" |
| 37 | + } |
| 38 | + "extendedRequestId" : "$context.extendedRequestId" |
| 39 | + "httpMethod" : "$context.httpMethod" |
| 40 | + "identity" : { |
| 41 | + "sourceIp" : "$context.identity.sourceIp" |
| 42 | + "userAgent" : "$context.identity.userAgent" |
| 43 | + } |
| 44 | + "integration" : { |
| 45 | + "error" : "$context.integration.error" |
| 46 | + "integrationStatus" : "$context.integration.integrationStatus" |
| 47 | + "latency" : "$context.integration.latency" |
| 48 | + "requestId" : "$context.integration.requestId" |
| 49 | + "status" : "$context.integration.status" |
| 50 | + } |
| 51 | + "path" : "$context.path" |
| 52 | + "protocol" : "$context.protocol" |
| 53 | + "requestId" : "$context.requestId" |
| 54 | + "requestTime" : "$context.requestTime" |
| 55 | + "requestTimeEpoch" : "$context.requestTimeEpoch" |
| 56 | + "responseLatency" : "$context.responseLatency" |
| 57 | + "responseLength" : "$context.responseLength" |
| 58 | + "resourceId" : "$context.resourceId" |
| 59 | + "resourcePath" : "$context.resourcePath" |
| 60 | + "stage" : "$context.stage" |
| 61 | + "status" : "$context.status" |
| 62 | + }) |
| 63 | + } |
| 64 | +} |
0 commit comments