-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapi-resource-info.tf
137 lines (114 loc) · 4.53 KB
/
api-resource-info.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
#
# getInfo API Function /info
#
resource "aws_api_gateway_resource" "info" {
path_part = "info"
parent_id = aws_api_gateway_rest_api.BeaconApi.root_resource_id
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
}
resource "aws_api_gateway_method" "info" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.info.id
http_method = "GET"
authorization = var.beacon-enable-auth ? "COGNITO_USER_POOLS" : "NONE"
authorizer_id = var.beacon-enable-auth ? aws_api_gateway_authorizer.BeaconUserPool-authorizer.id : null
}
resource "aws_api_gateway_method_response" "info" {
rest_api_id = aws_api_gateway_method.info.rest_api_id
resource_id = aws_api_gateway_method.info.resource_id
http_method = aws_api_gateway_method.info.http_method
status_code = "200"
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = true
}
response_models = {
"application/json" = "Empty"
}
}
#
# getInfo API Function /
#
resource "aws_api_gateway_method" "root-get" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_rest_api.BeaconApi.root_resource_id
http_method = "GET"
authorization = var.beacon-enable-auth ? "COGNITO_USER_POOLS" : "NONE"
authorizer_id = var.beacon-enable-auth ? aws_api_gateway_authorizer.BeaconUserPool-authorizer.id : null
}
resource "aws_api_gateway_method_response" "root-get" {
rest_api_id = aws_api_gateway_method.root-get.rest_api_id
resource_id = aws_api_gateway_method.root-get.resource_id
http_method = aws_api_gateway_method.root-get.http_method
status_code = "200"
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = true
}
response_models = {
"application/json" = "Empty"
}
}
# enable CORS
module "cors-info" {
source = "squidfunk/api-gateway-enable-cors/aws"
version = "0.3.3"
api_id = aws_api_gateway_rest_api.BeaconApi.id
api_resource_id = aws_api_gateway_resource.info.id
}
module "cors-info-root" {
source = "squidfunk/api-gateway-enable-cors/aws"
version = "0.3.3"
api_id = aws_api_gateway_rest_api.BeaconApi.id
api_resource_id = aws_api_gateway_method.root-get.resource_id
}
# wire up lambda
resource "aws_api_gateway_integration" "info" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.info.id
http_method = aws_api_gateway_method.info.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = module.lambda-getInfo.lambda_function_invoke_arn
}
resource "aws_api_gateway_integration_response" "info" {
rest_api_id = aws_api_gateway_method.info.rest_api_id
resource_id = aws_api_gateway_method.info.resource_id
http_method = aws_api_gateway_method.info.http_method
status_code = aws_api_gateway_method_response.info.status_code
response_templates = {
"application/json" = ""
}
depends_on = [aws_api_gateway_integration.info]
}
resource "aws_api_gateway_integration" "root-get" {
rest_api_id = aws_api_gateway_method.root-get.rest_api_id
resource_id = aws_api_gateway_method.root-get.resource_id
http_method = aws_api_gateway_method.root-get.http_method
type = "AWS_PROXY"
uri = module.lambda-getInfo.lambda_function_invoke_arn
integration_http_method = "POST"
}
resource "aws_api_gateway_integration_response" "root-get" {
rest_api_id = aws_api_gateway_method.root-get.rest_api_id
resource_id = aws_api_gateway_method.root-get.resource_id
http_method = aws_api_gateway_method.root-get.http_method
status_code = aws_api_gateway_method_response.root-get.status_code
response_templates = {
"application/json" = ""
}
depends_on = [aws_api_gateway_integration.root-get]
}
# permit lambda invokation
resource "aws_lambda_permission" "APIGetInfo" {
statement_id = "AllowAPIGetInfoInvoke"
action = "lambda:InvokeFunction"
function_name = module.lambda-getInfo.lambda_function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.BeaconApi.execution_arn}/*/*/${aws_api_gateway_resource.info.path_part}"
}
resource "aws_lambda_permission" "APIGetinfo-root" {
statement_id = "AllowAPIGetinfoRootInvoke"
action = "lambda:InvokeFunction"
function_name = module.lambda-getInfo.lambda_function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.BeaconApi.execution_arn}/*/*/"
}