-
Notifications
You must be signed in to change notification settings - Fork 463
/
gateway.tf
183 lines (151 loc) · 5.89 KB
/
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
## API Gateway
resource "aws_api_gateway_rest_api" "marlowe_symbolic_lambda" {
name = "marlowe_symbolic_lambda_${var.env}"
description = "API Gateway for the Marlowe Symbolic Lambda"
endpoint_configuration {
types = ["REGIONAL"]
}
binary_media_types = ["image/x-icon", "font/woff2", "font/ttf"]
}
resource "aws_api_gateway_resource" "marlowe_symbolic_proxy" {
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
parent_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.root_resource_id
path_part = "marlowe-analysis"
}
resource "aws_api_gateway_method" "marlowe_symbolic_proxy" {
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
resource_id = aws_api_gateway_resource.marlowe_symbolic_proxy.id
http_method = "POST"
authorization = "NONE"
api_key_required = false
}
resource "aws_api_gateway_integration" "marlowe_symbolic_lambda" {
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
resource_id = aws_api_gateway_method.marlowe_symbolic_proxy.resource_id
http_method = aws_api_gateway_method.marlowe_symbolic_proxy.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.marlowe_symbolic.invoke_arn
request_parameters = {
}
}
resource "aws_api_gateway_deployment" "marlowe_symbolic_lambda" {
depends_on = [
aws_api_gateway_integration.marlowe_symbolic_lambda,
]
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
stage_name = var.env
}
resource "aws_lambda_permission" "marlowe_symbolic_lambda_api_gw" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.marlowe_symbolic.function_name
principal = "apigateway.amazonaws.com"
# The "/*/*" portion grants access from any method on any resource
# within the API Gateway REST API.
source_arn = "${aws_api_gateway_rest_api.marlowe_symbolic_lambda.execution_arn}/*/*"
}
resource "aws_lambda_permission" "marlowe_playground_lambda_api_gw" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.marlowe_playground.function_name
principal = "apigateway.amazonaws.com"
# The "/*/*" portion grants access from any method on any resource
# within the API Gateway REST API.
source_arn = "${aws_api_gateway_rest_api.marlowe_symbolic_lambda.execution_arn}/*/*"
}
resource "aws_api_gateway_usage_plan" "marlowe_symbolic_lambda" {
name = "marlowe_symbolic_lambda_${var.env}"
api_stages {
api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
stage = aws_api_gateway_deployment.marlowe_symbolic_lambda.stage_name
}
quota_settings {
limit = 86400
offset = 0
period = "DAY"
}
}
resource "aws_api_gateway_domain_name" "marlowe_symbolic_lambda" {
domain_name = local.marlowe_domain_name
regional_certificate_arn = data.aws_acm_certificate.marlowe_private.arn
endpoint_configuration {
types = ["REGIONAL"]
}
}
resource "aws_api_gateway_base_path_mapping" "marlowe_symbolic_lambda" {
# The path, if not specified, is `/` by default
api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
stage_name = aws_api_gateway_deployment.marlowe_symbolic_lambda.stage_name
domain_name = aws_api_gateway_domain_name.marlowe_symbolic_lambda.domain_name
}
resource "aws_api_gateway_resource" "api" {
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
parent_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.root_resource_id
path_part = "api"
}
resource "aws_api_gateway_resource" "proxy" {
depends_on = [
aws_api_gateway_resource.api,
]
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
parent_id = aws_api_gateway_resource.api.id
path_part = "{proxy+}"
}
resource "aws_api_gateway_method" "proxy" {
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
resource_id = aws_api_gateway_resource.proxy.id
http_method = "ANY"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "proxy" {
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
resource_id = aws_api_gateway_method.proxy.resource_id
http_method = aws_api_gateway_method.proxy.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.marlowe_playground.invoke_arn
request_parameters = {
}
}
# runghc proxy
resource "aws_api_gateway_resource" "runghc" {
depends_on = [
aws_api_gateway_resource.api,
]
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
parent_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.root_resource_id
path_part = "runghc"
}
resource "aws_api_gateway_method" "runghc" {
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
resource_id = aws_api_gateway_resource.runghc.id
http_method = "POST"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "runghc" {
rest_api_id = aws_api_gateway_rest_api.marlowe_symbolic_lambda.id
resource_id = aws_api_gateway_method.runghc.resource_id
http_method = aws_api_gateway_method.runghc.http_method
integration_http_method = "POST"
type = "HTTP_PROXY"
uri = "http://${aws_alb.plutus.dns_name}/runghc"
request_parameters = {
}
}
resource "aws_route53_record" "lambda" {
name = local.marlowe_domain_name
type = "A"
zone_id = "${var.marlowe_public_zone}"
alias {
name = "${aws_api_gateway_domain_name.marlowe_symbolic_lambda.regional_domain_name}"
zone_id = "${aws_api_gateway_domain_name.marlowe_symbolic_lambda.regional_zone_id}"
evaluate_target_health = true
}
}
output "rest_api_id" {
value = "${aws_api_gateway_rest_api.marlowe_symbolic_lambda.id}"
}
output "region" {
value = "${var.aws_region}"
}