-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_gw.tf
75 lines (61 loc) · 2.44 KB
/
api_gw.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
resource "aws_api_gateway_rest_api" "jigsaw_api" {
name = "jigsaw-api"
description = "API Gateway for the jigsaw Lambda function"
# pass client ip to the backend
endpoint_configuration {
types = ["REGIONAL"]
}
}
resource "aws_api_gateway_resource" "jigsaw_resource" {
rest_api_id = aws_api_gateway_rest_api.jigsaw_api.id
parent_id = aws_api_gateway_rest_api.jigsaw_api.root_resource_id
path_part = "jigsaw"
}
resource "aws_api_gateway_method" "jigsaw_method" {
rest_api_id = aws_api_gateway_rest_api.jigsaw_api.id
resource_id = aws_api_gateway_resource.jigsaw_resource.id
http_method = "GET"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "jigsaw_integration" {
rest_api_id = aws_api_gateway_rest_api.jigsaw_api.id
resource_id = aws_api_gateway_resource.jigsaw_resource.id
http_method = aws_api_gateway_method.jigsaw_method.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.jigsaw.invoke_arn
}
resource "aws_api_gateway_resource" "jigsaw_resource2" {
rest_api_id = aws_api_gateway_rest_api.jigsaw_api.id
parent_id = aws_api_gateway_rest_api.jigsaw_api.root_resource_id
path_part = "{proxy+}"
}
resource "aws_api_gateway_method" "jigsaw_method2" {
rest_api_id = aws_api_gateway_rest_api.jigsaw_api.id
resource_id = aws_api_gateway_resource.jigsaw_resource2.id
http_method = "GET"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "jigsaw_integration2" {
rest_api_id = aws_api_gateway_rest_api.jigsaw_api.id
resource_id = aws_api_gateway_resource.jigsaw_resource2.id
http_method = aws_api_gateway_method.jigsaw_method2.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.jigsaw.invoke_arn
}
resource "aws_lambda_permission" "apigw_lambda" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.jigsaw.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.jigsaw_api.execution_arn}/*/*"
}
resource "aws_api_gateway_deployment" "jigsaw_deployment" {
depends_on = [aws_api_gateway_integration.jigsaw_integration2]
rest_api_id = aws_api_gateway_rest_api.jigsaw_api.id
stage_name = "prod"
}
output "api_url" {
value = "${aws_api_gateway_deployment.jigsaw_deployment.invoke_url}"
}