-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_gateway.tf
94 lines (77 loc) · 2.36 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Create REST API
resource "aws_api_gateway_rest_api" "api" {
depends_on = [
aws_lambda_function.wordpress
]
name = "${var.project_name}-rest-api"
description = "API Gateway for ${var.project_name}"
binary_media_types = [
"*/*"
]
}
# /{proxy+} resource
resource "aws_api_gateway_resource" "proxy" {
depends_on = [
aws_api_gateway_rest_api.api
]
rest_api_id = aws_api_gateway_rest_api.api.id
parent_id = aws_api_gateway_rest_api.api.root_resource_id
path_part = "{proxy+}"
}
# ANY method for / resource
resource "aws_api_gateway_method" "root_any" {
depends_on = [
aws_api_gateway_rest_api.api
]
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_rest_api.api.root_resource_id
http_method = "ANY"
authorization = "NONE"
}
# ANY method for /{proxy+} resource
resource "aws_api_gateway_method" "proxy_any" {
depends_on = [
aws_api_gateway_resource.proxy,
aws_api_gateway_rest_api.api
]
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.proxy.id
http_method = "ANY"
authorization = "NONE"
}
# ANY integration for /{proxy+} resource
resource "aws_api_gateway_integration" "proxy_integration" {
depends_on = [
aws_api_gateway_method.proxy_any,
aws_api_gateway_rest_api.api
]
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.proxy.id
http_method = aws_api_gateway_method.proxy_any.http_method
type = "AWS_PROXY"
integration_http_method = "POST"
uri = aws_lambda_function.wordpress.invoke_arn
}
# ANY integration for / resource
resource "aws_api_gateway_integration" "root_integration" {
depends_on = [
aws_api_gateway_method.root_any,
aws_api_gateway_rest_api.api
]
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_rest_api.api.root_resource_id
http_method = aws_api_gateway_method.root_any.http_method
type = "AWS_PROXY"
integration_http_method = "POST"
uri = aws_lambda_function.wordpress.invoke_arn
}
# API Gateway Deployment
resource "aws_api_gateway_deployment" "api" {
depends_on = [
aws_api_gateway_rest_api.api,
aws_api_gateway_integration.proxy_integration,
aws_api_gateway_integration.root_integration
]
rest_api_id = aws_api_gateway_rest_api.api.id
stage_name = "prod"
}