-
Notifications
You must be signed in to change notification settings - Fork 5
/
api-filtering-terms.tf
72 lines (61 loc) · 2.63 KB
/
api-filtering-terms.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
#
# GetFilteringTerms API Function /filtering_terms
#
resource "aws_api_gateway_resource" "filtering_terms" {
path_part = "filtering_terms"
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" "filtering_terms" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.filtering_terms.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" "filtering_terms" {
rest_api_id = aws_api_gateway_method.filtering_terms.rest_api_id
resource_id = aws_api_gateway_method.filtering_terms.resource_id
http_method = aws_api_gateway_method.filtering_terms.http_method
status_code = "200"
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = true
}
response_models = {
"application/json" = "Empty"
}
}
# enable CORS
module "cors-filtering_terms" {
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.filtering_terms.id
}
# wire up lambda
resource "aws_api_gateway_integration" "filtering_terms" {
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
resource_id = aws_api_gateway_resource.filtering_terms.id
http_method = aws_api_gateway_method.filtering_terms.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = module.lambda-getFilteringTerms.lambda_function_invoke_arn
}
resource "aws_api_gateway_integration_response" "filtering_terms" {
rest_api_id = aws_api_gateway_method.filtering_terms.rest_api_id
resource_id = aws_api_gateway_method.filtering_terms.resource_id
http_method = aws_api_gateway_method.filtering_terms.http_method
status_code = aws_api_gateway_method_response.filtering_terms.status_code
response_templates = {
"application/json" = ""
}
depends_on = [aws_api_gateway_integration.filtering_terms]
}
# permit lambda invokation
resource "aws_lambda_permission" "APIGetFilteringTerms" {
statement_id = "AllowAPIGetFilteringTermsInvoke"
action = "lambda:InvokeFunction"
function_name = module.lambda-getFilteringTerms.lambda_function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.BeaconApi.execution_arn}/*/*/${aws_api_gateway_resource.filtering_terms.path_part}"
}