-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda.tf
57 lines (49 loc) · 1.43 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
data "archive_file" "lambdazip" {
type = "zip"
output_path = "${path.module}/lambda_function.zip"
source_dir = "${path.module}/lambda"
}
resource "aws_lambda_function" "lambda" {
provider = aws.aws_us_east_1
function_name = "country-based-url-rewriter"
role = aws_iam_role.lambda.arn
publish = true
runtime = "nodejs16.x"
handler = "index.handler"
memory_size = 128
timeout = 5
filename = data.archive_file.lambdazip.output_path
source_code_hash = data.archive_file.lambdazip.output_base64sha256
}
data "aws_iam_policy_document" "assume_role_policy" {
version = "2012-10-17"
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
identifiers = ["lambda.amazonaws.com", "edgelambda.amazonaws.com"]
type = "Service"
}
}
}
data "aws_iam_policy_document" "role_policy" {
version = "2012-10-17"
statement {
effect = "Allow"
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = ["arn:aws:logs:*:*:*"]
}
}
resource "aws_iam_role" "lambda" {
name = "country-based-url-rewriter-lambda-role"
assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json
}
resource "aws_iam_role_policy" "cloudwatch" {
name = "cloudwatch"
role = aws_iam_role.lambda.id
policy = data.aws_iam_policy_document.role_policy.json
}