-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
62 lines (52 loc) · 1.83 KB
/
main.tf
File metadata and controls
62 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
resource "aws_apigatewayv2_api" "health_api" {
name = "${var.environment}-serverless-health-check-api"
protocol_type = "HTTP"
cors_configuration {
allow_origins = ["*"]
allow_methods = ["GET", "POST", "OPTIONS"]
allow_headers = ["*"]
}
tags = var.common_tags
}
resource "aws_apigatewayv2_integration" "lambda_integration" {
api_id = aws_apigatewayv2_api.health_api.id
integration_type = "AWS_PROXY"
integration_method = "POST"
payload_format_version = "2.0"
integration_uri = var.lambda_invoke_arn
depends_on = []
}
resource "aws_apigatewayv2_route" "health_route_get" {
api_id = aws_apigatewayv2_api.health_api.id
route_key = "GET /health"
target = "integrations/${aws_apigatewayv2_integration.lambda_integration.id}"
}
resource "aws_apigatewayv2_route" "health_route_post" {
api_id = aws_apigatewayv2_api.health_api.id
route_key = "POST /health"
target = "integrations/${aws_apigatewayv2_integration.lambda_integration.id}"
}
resource "aws_apigatewayv2_stage" "default" {
api_id = aws_apigatewayv2_api.health_api.id
name = "$default"
auto_deploy = true
access_log_settings {
destination_arn = aws_cloudwatch_log_group.api_gateway_logs.arn
format = jsonencode({
requestId = "$context.requestId"
ip = "$context.identity.sourceIp"
requestTime = "$context.requestTime"
httpMethod = "$context.httpMethod"
resourcePath = "$context.resourcePath"
status = "$context.status"
protocol = "$context.protocol"
responseLength = "$context.responseLength"
})
}
tags = var.common_tags
}
resource "aws_cloudwatch_log_group" "api_gateway_logs" {
name = "/aws/apigateway/${var.environment}-serverless-health-check-api"
retention_in_days = 7
tags = var.common_tags
}