-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapigw.tf
65 lines (57 loc) · 2 KB
/
apigw.tf
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
63
64
65
resource "aws_apigatewayv2_api" "api" {
name = "${var.prefix}-gateway"
protocol_type = "WEBSOCKET"
target = aws_lambda_function.apigw.invoke_arn
route_selection_expression = "$request.body.action"
}
resource "aws_apigatewayv2_route" "default" {
api_id = aws_apigatewayv2_api.api.id
route_key = "$default"
target = "integrations/${aws_apigatewayv2_integration.api.id}"
}
resource "aws_apigatewayv2_route" "connect" {
api_id = aws_apigatewayv2_api.api.id
route_key = "$connect"
target = "integrations/${aws_apigatewayv2_integration.api.id}"
}
resource "aws_apigatewayv2_integration" "api" {
api_id = aws_apigatewayv2_api.api.id
integration_type = "AWS_PROXY"
connection_type = "INTERNET"
content_handling_strategy = "CONVERT_TO_TEXT"
description = "Lambda example"
integration_method = "POST"
integration_uri = aws_lambda_function.apigw.invoke_arn
passthrough_behavior = "WHEN_NO_MATCH"
}
resource "aws_cloudwatch_log_group" "api_logs" {
name = "${var.prefix}-gateway/logs"
retention_in_days = 30
}
resource "aws_apigatewayv2_stage" "stage" {
api_id = aws_apigatewayv2_api.api.id
name = "production"
auto_deploy = true
access_log_settings {
destination_arn = aws_cloudwatch_log_group.api_logs.arn
format = jsonencode(
{
httpMethod = "$context.httpMethod"
ip = "$context.identity.sourceIp"
protocol = "$context.protocol"
requestId = "$context.requestId"
requestTime = "$context.requestTime"
responseLength = "$context.responseLength"
routeKey = "$context.routeKey"
status = "$context.status"
}
)
}
default_route_settings {
data_trace_enabled = true
detailed_metrics_enabled = false
logging_level = "INFO"
throttling_burst_limit = 5000
throttling_rate_limit = 10000
}
}