-
Notifications
You must be signed in to change notification settings - Fork 5
/
api-submit-cohort.tf
146 lines (122 loc) · 5.31 KB
/
api-submit-cohort.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
#
# submit cohort API Function /submit-cohort
#
resource "aws_api_gateway_resource" "submit-cohort" {
path_part = "submit_cohort"
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" "submit-cohort_post" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.submit-cohort.id
http_method = "POST"
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" "submit-cohort_post" {
rest_api_id = aws_api_gateway_method.submit-cohort_post.rest_api_id
resource_id = aws_api_gateway_method.submit-cohort_post.resource_id
http_method = aws_api_gateway_method.submit-cohort_post.http_method
status_code = "200"
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = true
}
response_models = {
"application/json" = "Empty"
}
}
#
# Update cohort /submit-cohort/{id}
#
resource "aws_api_gateway_resource" "submit-cohort-id" {
path_part = "{id}"
parent_id = aws_api_gateway_resource.submit-cohort.id
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
}
resource "aws_api_gateway_method" "submit-cohort-id_post" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.submit-cohort-id.id
http_method = "POST"
authorization = var.beacon-enable-auth ? "COGNITO_USER_POOLS" : "NONE"
authorizer_id = var.beacon-enable-auth ? aws_api_gateway_authorizer.BeaconUserPool-authorizer.id : null
request_parameters = {
"method.request.path.id" = true
}
}
resource "aws_api_gateway_method_response" "submit-cohort-id_post" {
rest_api_id = aws_api_gateway_method.submit-cohort-id_post.rest_api_id
resource_id = aws_api_gateway_method.submit-cohort-id_post.resource_id
http_method = aws_api_gateway_method.submit-cohort-id_post.http_method
status_code = "200"
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = true
}
response_models = {
"application/json" = "Empty"
}
}
# enable CORS
module "cors-submit-cohort" {
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.submit-cohort.id
}
module "cors-submit-cohort-id" {
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.submit-cohort-id.id
}
# wire up lambda submit-cohort
resource "aws_api_gateway_integration" "submit-cohort_post" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.submit-cohort.id
http_method = aws_api_gateway_method.submit-cohort_post.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = module.lambda-submitDataset.lambda_function_invoke_arn
}
resource "aws_api_gateway_integration_response" "submit-cohort_post" {
rest_api_id = aws_api_gateway_method.submit-cohort_post.rest_api_id
resource_id = aws_api_gateway_method.submit-cohort_post.resource_id
http_method = aws_api_gateway_method.submit-cohort_post.http_method
status_code = aws_api_gateway_method_response.submit-cohort_post.status_code
response_templates = {
"application/json" = ""
}
depends_on = [aws_api_gateway_integration.submit-cohort_post]
}
resource "aws_api_gateway_integration" "submit-cohort-id_post" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.submit-cohort-id.id
http_method = aws_api_gateway_method.submit-cohort-id_post.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = module.lambda-submitDataset.lambda_function_invoke_arn
}
resource "aws_api_gateway_integration_response" "submit-cohort-id_post" {
rest_api_id = aws_api_gateway_method.submit-cohort-id_post.rest_api_id
resource_id = aws_api_gateway_method.submit-cohort-id_post.resource_id
http_method = aws_api_gateway_method.submit-cohort-id_post.http_method
status_code = aws_api_gateway_method_response.submit-cohort-id_post.status_code
response_templates = {
"application/json" = ""
}
depends_on = [aws_api_gateway_integration.submit-cohort-id_post]
}
# permit lambda invokation
resource "aws_lambda_permission" "APIsubmit-cohort" {
statement_id = "AllowAPIsubmit-cohortInvoke"
action = "lambda:InvokeFunction"
function_name = module.lambda-submitDataset.lambda_function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.BeaconApi.execution_arn}/*/*/${aws_api_gateway_resource.submit-cohort.path_part}"
}
resource "aws_lambda_permission" "APIsubmit-cohortId" {
statement_id = "AllowAPIsubmit-cohortIdInvoke"
action = "lambda:InvokeFunction"
function_name = module.lambda-submitDataset.lambda_function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.BeaconApi.execution_arn}/*/*/${aws_api_gateway_resource.submit-cohort.path_part}/*"
}