-
Notifications
You must be signed in to change notification settings - Fork 5
/
api-submit-dataset.tf
146 lines (122 loc) · 5.36 KB
/
api-submit-dataset.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 dataset API Function /submit-dataset
#
resource "aws_api_gateway_resource" "submit-dataset" {
path_part = "submit_dataset"
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-dataset_post" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.submit-dataset.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-dataset_post" {
rest_api_id = aws_api_gateway_method.submit-dataset_post.rest_api_id
resource_id = aws_api_gateway_method.submit-dataset_post.resource_id
http_method = aws_api_gateway_method.submit-dataset_post.http_method
status_code = "200"
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = true
}
response_models = {
"application/json" = "Empty"
}
}
#
# Update dataset /submit-dataset/{id}
#
resource "aws_api_gateway_resource" "submit-dataset-id" {
path_part = "{id}"
parent_id = aws_api_gateway_resource.submit-dataset.id
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
}
resource "aws_api_gateway_method" "submit-dataset-id_post" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.submit-dataset-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-dataset-id_post" {
rest_api_id = aws_api_gateway_method.submit-dataset-id_post.rest_api_id
resource_id = aws_api_gateway_method.submit-dataset-id_post.resource_id
http_method = aws_api_gateway_method.submit-dataset-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-dataset" {
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-dataset.id
}
module "cors-submit-dataset-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-dataset-id.id
}
# wire up lambda submit-dataset
resource "aws_api_gateway_integration" "submit-dataset_post" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.submit-dataset.id
http_method = aws_api_gateway_method.submit-dataset_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-dataset_post" {
rest_api_id = aws_api_gateway_method.submit-dataset_post.rest_api_id
resource_id = aws_api_gateway_method.submit-dataset_post.resource_id
http_method = aws_api_gateway_method.submit-dataset_post.http_method
status_code = aws_api_gateway_method_response.submit-dataset_post.status_code
response_templates = {
"application/json" = ""
}
depends_on = [aws_api_gateway_integration.submit-dataset_post]
}
resource "aws_api_gateway_integration" "submit-dataset-id_post" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.submit-dataset-id.id
http_method = aws_api_gateway_method.submit-dataset-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-dataset-id_post" {
rest_api_id = aws_api_gateway_method.submit-dataset-id_post.rest_api_id
resource_id = aws_api_gateway_method.submit-dataset-id_post.resource_id
http_method = aws_api_gateway_method.submit-dataset-id_post.http_method
status_code = aws_api_gateway_method_response.submit-dataset-id_post.status_code
response_templates = {
"application/json" = ""
}
depends_on = [aws_api_gateway_integration.submit-dataset-id_post]
}
# permit lambda invokation
resource "aws_lambda_permission" "APIsubmit-dataset" {
statement_id = "AllowAPIsubmit-datasetInvoke"
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-dataset.path_part}"
}
resource "aws_lambda_permission" "APIsubmit-datasetId" {
statement_id = "AllowAPIsubmit-datasetIdInvoke"
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-dataset.path_part}/*"
}