-
Notifications
You must be signed in to change notification settings - Fork 4
/
lambda-processor.tf
64 lines (57 loc) · 1.82 KB
/
lambda-processor.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
resource "aws_lambda_function" "lambda_processor" {
filename = "${path.module}/${var.firehose_lambda_processor_name}.zip"
function_name = var.firehose_lambda_processor_name
role = aws_iam_role.lambda_iam.arn
description = "An Amazon Kinesis Firehose stream processor that extracts individual log events from records sent by Cloudwatch Logs subscription filters."
handler = "lambda_function.handler"
runtime = "python3.8"
source_code_hash = data.archive_file.lambda_processor_zip.output_base64sha256
timeout = 180
depends_on = [
aws_iam_role_policy_attachment.lambda_logs,
aws_cloudwatch_log_group.firehose_lambda_delivery
]
}
resource "aws_iam_role" "lambda_iam" {
name = "lambda_iam"
assume_role_policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Action" : "sts:AssumeRole",
"Principal" : {
"Service" : "lambda.amazonaws.com"
},
"Effect" : "Allow",
"Sid" : ""
}
]
})
}
resource "aws_cloudwatch_log_group" "firehose_lambda_delivery" {
name = "/aws/lambda/${var.firehose_lambda_processor_name}"
retention_in_days = 14
}
resource "aws_iam_policy" "lambda_processor_logging" {
name = "lambda_processor_logging"
path = "/"
description = "IAM policy for logging from a lambda"
policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Action" : [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource" : "arn:aws:logs:*:*:*",
"Effect" : "Allow"
}
]
})
}
resource "aws_iam_role_policy_attachment" "lambda_logs" {
role = aws_iam_role.lambda_iam.name
policy_arn = aws_iam_policy.lambda_processor_logging.arn
}