-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmain.tf
More file actions
99 lines (82 loc) · 2.62 KB
/
main.tf
File metadata and controls
99 lines (82 loc) · 2.62 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
resource "aws_api_gateway_rest_api" "rest" {
name = "Rest API"
}
resource "aws_api_gateway_resource" "proxy" {
rest_api_id = aws_api_gateway_rest_api.rest.id
parent_id = aws_api_gateway_rest_api.rest.root_resource_id
path_part = "{proxy+}"
}
resource "aws_api_gateway_method" "method_get" {
rest_api_id = aws_api_gateway_rest_api.rest.id
resource_id = aws_api_gateway_resource.proxy.id
http_method = "GET"
authorization = "NONE"
}
resource "aws_api_gateway_method" "method_post" {
rest_api_id = aws_api_gateway_rest_api.rest.id
resource_id = aws_api_gateway_resource.proxy.id
http_method = "POST"
authorization = "CUSTOM"
authorizer_id = aws_api_gateway_authorizer.demo.id
}
resource "aws_api_gateway_authorizer" "demo" {
name = "jwt"
rest_api_id = aws_api_gateway_rest_api.rest.id
authorizer_uri = aws_lambda_function.authorizer.invoke_arn
authorizer_credentials = aws_iam_role.role.arn
}
resource "aws_lambda_function" "authorizer" {
filename = "authorizer-function.zip"
function_name = "api_gateway_authorizer"
role = aws_iam_role.role.arn
handler = "authorizer.handler"
source_code_hash = filebase64sha256("authorizer-function.zip")
runtime = "nodejs18.x"
}
resource "aws_api_gateway_integration" "integration" {
rest_api_id = aws_api_gateway_rest_api.rest.id
resource_id = aws_api_gateway_resource.proxy.id
http_method = aws_api_gateway_method.method_get.http_method
type = "HTTP_PROXY"
integration_http_method = "POST"
uri = "http://httpbin.org/anything/{proxy}"
}
resource "aws_api_gateway_integration" "integration_post" {
rest_api_id = aws_api_gateway_rest_api.rest.id
resource_id = aws_api_gateway_resource.proxy.id
http_method = aws_api_gateway_method.method_post.http_method
integration_http_method = "ANY"
type = "AWS_PROXY"
uri = aws_lambda_function.lambda.invoke_arn
}
resource "aws_lambda_function" "lambda" {
filename = "lambda.zip"
function_name = "mylambda"
role = aws_iam_role.role.arn
handler = "lambda.handler"
source_code_hash = filebase64sha256("lambda.zip")
runtime = "nodejs18.x"
environment {
variables = {
foo = "bar"
}
}
}
resource "aws_iam_role" "role" {
name = "myrole"
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY
}