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