This repository has been archived by the owner on Apr 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
apigateway.tf
79 lines (64 loc) · 3.12 KB
/
apigateway.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
resource "aws_api_gateway_rest_api" "exampleLambdaGateway" {
name = "${var.function_name}-gateway"
description = "Terraform Serverless Example Gateway"
}
resource "aws_api_gateway_resource" "exampleLambdaGatewayProxy" {
rest_api_id = "${aws_api_gateway_rest_api.exampleLambdaGateway.id}"
parent_id = "${aws_api_gateway_rest_api.exampleLambdaGateway.root_resource_id}"
path_part = "{proxy+}"
}
resource "aws_api_gateway_method" "exampleLambdaGatewayMethod" {
rest_api_id = "${aws_api_gateway_rest_api.exampleLambdaGateway.id}"
resource_id = "${aws_api_gateway_resource.exampleLambdaGatewayProxy.id}"
http_method = "ANY"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "exampleLambdaGatewayIntegration" {
rest_api_id = "${aws_api_gateway_rest_api.exampleLambdaGateway.id}"
resource_id = "${aws_api_gateway_method.exampleLambdaGatewayMethod.resource_id}"
http_method = "${aws_api_gateway_method.exampleLambdaGatewayMethod.http_method}"
integration_http_method = "POST"
type = "AWS_PROXY"
uri = "${aws_lambda_function.exampleLambdaFunction.invoke_arn}"
}
resource "aws_api_gateway_method" "exampleLambdaGatewayMethodRoot" {
rest_api_id = "${aws_api_gateway_rest_api.exampleLambdaGateway.id}"
resource_id = "${aws_api_gateway_rest_api.exampleLambdaGateway.root_resource_id}"
http_method = "ANY"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "exampleLambdaGatewayIntegrationRoot" {
rest_api_id = "${aws_api_gateway_rest_api.exampleLambdaGateway.id}"
resource_id = "${aws_api_gateway_method.exampleLambdaGatewayMethodRoot.resource_id}"
http_method = "${aws_api_gateway_method.exampleLambdaGatewayMethodRoot.http_method}"
integration_http_method = "POST"
type = "AWS_PROXY"
uri = "${aws_lambda_function.exampleLambdaFunction.invoke_arn}"
}
resource "aws_api_gateway_deployment" "exampleLambdaGatewayDeployment" {
depends_on = [
"aws_api_gateway_integration.exampleLambdaGatewayIntegration",
"aws_api_gateway_integration.exampleLambdaGatewayIntegrationRoot",
]
rest_api_id = "${aws_api_gateway_rest_api.exampleLambdaGateway.id}"
stage_name = "${var.api_stage_name}"
}
resource "aws_lambda_permission" "exampleLambdaGatewayPermission" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.exampleLambdaFunction.arn}"
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_deployment.exampleLambdaGatewayDeployment.execution_arn}/*/*"
}
resource "aws_api_gateway_domain_name" "exampleGatewayDN" {
domain_name = "${var.example_host}.${var.base_zone}"
certificate_arn = "${aws_acm_certificate_validation.exampleSubdomainCert.certificate_arn}"
}
resource "aws_api_gateway_base_path_mapping" "exampleGatewayMapping" {
api_id = "${aws_api_gateway_rest_api.exampleLambdaGateway.id}"
stage_name = "${aws_api_gateway_deployment.exampleLambdaGatewayDeployment.stage_name}"
domain_name = "${aws_api_gateway_domain_name.exampleGatewayDN.domain_name}"
}
output "base_url" {
value = "${aws_api_gateway_deployment.exampleLambdaGatewayDeployment.invoke_url}"
}