Repository navigation
Expand file tree
/
Copy pathgateway.tf
More file actions
77 lines (68 loc) · 2.77 KB
/
Copy pathgateway.tf
File metadata and controls
77 lines (68 loc) · 2.77 KB
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
resource "aws_api_gateway_rest_api" "api_gateway" {
name = "APIGateway"
description = "API Gateway for Lambda"
tags = {
environment = "local"
_custom_id_ = "api"
}
}
resource "aws_api_gateway_authorizer" "lambda_authorizer" {
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
name = "LambdaAuthorizer"
type = "TOKEN"
authorizer_uri = module.lambda_auth.invoke_arn
authorizer_credentials = aws_iam_role.iam_for_lambda_tf.arn
identity_source = "method.request.header.Authorization"
}
resource "aws_lambda_permission" "authorizer_permission" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = module.lambda_auth.name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.api_gateway.execution_arn}/authorizers/${aws_api_gateway_authorizer.lambda_authorizer.id}"
}
// API
// API - Resources
# resource "aws_api_gateway_resource" "timeslots_root" {
# rest_api_id = aws_api_gateway_rest_api.api_gateway.id
# parent_id = aws_api_gateway_rest_api.api_gateway.root_resource_id
# path_part = "timeslots"
# }
resource "aws_api_gateway_resource" "timeslots_proxy" {
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
parent_id = aws_api_gateway_rest_api.api_gateway.root_resource_id
path_part = "{proxy+}"
}
// API - Methods
resource "aws_api_gateway_method" "any_timeslots_proxy_methods" {
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
resource_id = aws_api_gateway_resource.timeslots_proxy.id
http_method = "ANY"
authorization = "CUSTOM"
authorizer_id = aws_api_gateway_authorizer.lambda_authorizer.id
}
// API - Integrations
resource "aws_api_gateway_integration" "any_timeslots_proxy_integration" {
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
resource_id = aws_api_gateway_resource.timeslots_proxy.id
http_method = aws_api_gateway_method.any_timeslots_proxy_methods.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = module.lambda_timeslots.timeslots_invoke_arn
}
// API - Permissions
resource "aws_lambda_permission" "api_gateway_permission_timeslots" {
statement_id = "AllowAPIGatewayInvokeGetTimeslots"
action = "lambda:InvokeFunction"
function_name = module.lambda_timeslots.timeslots_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.api_gateway.execution_arn}/*/*"
}
// API - deployment
resource "aws_api_gateway_deployment" "api_deployment" {
depends_on = [
aws_api_gateway_integration.any_timeslots_proxy_integration
]
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
stage_name = var.stage
}