-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmain.tf
More file actions
96 lines (80 loc) · 2.72 KB
/
main.tf
File metadata and controls
96 lines (80 loc) · 2.72 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
# curl -X POST "a750e94d.execute-api.localhost.localstack.cloud:4566/example/test" -H 'content-type: application/json' -d '{ "greeter": "cesar" }'
resource "aws_apigatewayv2_api" "example" {
name = "example-http-api"
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_authorizer" "example" {
api_id = aws_apigatewayv2_api.example.id
authorizer_type = "REQUEST"
authorizer_uri = aws_lambda_function.lambda_auth.invoke_arn
identity_sources = ["$request.header.Authorization"]
name = "example-authorizer"
authorizer_payload_format_version = "2.0"
}
resource "aws_apigatewayv2_integration" "example" {
api_id = aws_apigatewayv2_api.example.id
integration_type = "AWS_PROXY"
payload_format_version = "2.0"
description = "Lambda example"
integration_method = "ANY"
integration_uri = aws_lambda_function.lambda.invoke_arn
request_parameters = {
"overwrite:header.x-syna-accountalias" : "$context.authorizer.accountAlias"
"overwrite:header.x-syna-accountid" : "$context.authorizer.accountId"
"overwrite:header.x-syna-permissions" : "$context.authorizer.permissions"
"overwrite:header.x-syna-projectid" : "$context.authorizer.projectId"
"overwrite:header.x-syna-tenantid" : "$context.authorizer.tenantId"
"overwrite:header.x-syna-userid" : "$context.authorizer.userId"
}
}
resource "aws_apigatewayv2_route" "example" {
api_id = aws_apigatewayv2_api.example.id
route_key = "ANY /example/{proxy+}"
authorization_type = "CUSTOM"
authorizer_id = aws_apigatewayv2_authorizer.example.id
target = "integrations/${aws_apigatewayv2_integration.example.id}"
}
resource "aws_lambda_function" "lambda_auth" {
filename = "lambda-auth.zip"
function_name = "lambda-auth"
role = aws_iam_role.role.arn
handler = "lambda-auth.handler"
source_code_hash = filebase64sha256("lambda-auth.zip")
runtime = "nodejs12.x"
environment {
variables = {
foo = "bar"
}
}
}
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 = "nodejs12.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
}