/
lambda.tf
69 lines (57 loc) · 2.24 KB
/
lambda.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
data "archive_file" "zip" {
type = "zip"
source_file = "../lambda/hello.js"
output_path = "../lambda/hello.zip"
}
resource "aws_lambda_function" "hello" {
filename = data.archive_file.zip.output_path
source_code_hash = filebase64sha256(data.archive_file.zip.output_path)
function_name = var.project_name
role = aws_iam_role.lambda_role.arn
handler = "hello.handler"
runtime = "nodejs12.x"
timeout = 10
# publish = true
}
resource "aws_lambda_alias" "alias_dev" {
name = "dev"
description = "dev"
function_name = aws_lambda_function.hello.arn
function_version = "$LATEST"
}
resource "aws_lambda_alias" "alias_prod" {
name = "prod"
description = "prod"
function_name = aws_lambda_function.hello.arn
function_version = "$LATEST"
}
resource "aws_lambda_permission" "lambda_permission" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.hello.function_name
principal = "apigateway.amazonaws.com"
# The "/*/*" portion grants access from any method on any resource
# within the API Gateway REST API.
source_arn = "${aws_api_gateway_rest_api.api_gateway.execution_arn}/*/*"
}
resource "aws_lambda_permission" "permission_dev" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.hello.function_name}:dev"
principal = "apigateway.amazonaws.com"
# The "/*/*" portion grants access from any method on any resource
# within the API Gateway REST API.
source_arn = "${aws_api_gateway_rest_api.api_gateway.execution_arn}/*/GET/hello"
}
resource "aws_lambda_permission" "permission_prod" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.hello.function_name}:prod"
principal = "apigateway.amazonaws.com"
# The "/*/*" portion grants access from any method on any resource
# within the API Gateway REST API.
source_arn = "${aws_api_gateway_rest_api.api_gateway.execution_arn}/*/GET/hello"
}
resource "aws_cloudwatch_log_group" "convert_log_group" {
name = "/aws/lambda/${aws_lambda_function.hello.function_name}"
}