-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapi_gateway.tf
44 lines (38 loc) · 1.33 KB
/
api_gateway.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
resource "aws_apigatewayv2_api" "main" {
name = local.lambda_function_name
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_route" "main_lambda" {
api_id = aws_apigatewayv2_api.main.id
route_key = "$default"
target = "integrations/${aws_apigatewayv2_integration.main_lambda.id}"
}
resource "aws_apigatewayv2_integration" "main_lambda" {
api_id = aws_apigatewayv2_api.main.id
integration_type = "AWS_PROXY"
payload_format_version = "1.0" # our PHP layer expects the 1.0 format
connection_type = "INTERNET"
integration_method = "POST"
integration_uri = aws_lambda_function.phpserver.invoke_arn
}
resource "aws_apigatewayv2_stage" "main_default" {
api_id = aws_apigatewayv2_api.main.id
name = "$default"
auto_deploy = true
default_route_settings {
throttling_burst_limit = 100
throttling_rate_limit = 100
}
lifecycle {
ignore_changes = [
deployment_id
]
}
}
resource "aws_lambda_permission" "main_phpserver" {
statement_id = "AllowHTTPAPIInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.phpserver.arn
principal = "apigateway.amazonaws.com"
source_arn = "arn:aws:execute-api:${var.region}:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.main.id}/*/$default"
}