-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAWS_Lambda.tf
83 lines (75 loc) · 2.08 KB
/
AWS_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
resource "aws_iam_policy" "lambda_policy" {
name = "lambda_policy"
description = "IAM policy for Lambda execution"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
Resource = "*"
},
{
Effect = "Allow",
Action = [
"kinesis:GetRecords",
"kinesis:GetShardIterator",
"kinesis:DescribeStream",
"kinesis:ListStreams"
],
Resource = "*"
},
{
Effect = "Allow",
Action = [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket"
],
Resource = [
"${aws_s3_bucket.data_bucket.arn}",
"${aws_s3_bucket.data_bucket.arn}/*"
]
},
{
Effect = "Allow",
Action = "es:*",
Resource = "*"
},
{
Effect = "Allow",
Action = "sns:Publish",
Resource = "*"
}
]
})
}
resource "aws_iam_role_policy_attachment" "lambda_policy_attachment" {
role = aws_iam_role.lambda_role.name
policy_arn = aws_iam_policy.lambda_policy.arn
}
# Create Lambda function
resource "aws_lambda_function" "process_kinesis" {
filename = "lambda_function_payload.zip" # Replace with your Lambda deployment package
function_name = "ProcessKinesisStream"
role = aws_iam_role.lambda_role.arn
handler = "index.handler"
runtime = "nodejs14.x" # Adjust runtime as needed
source_code_hash = filebase64sha256("lambda_function_payload.zip")
environment {
variables = {
BUCKET_NAME = aws_s3_bucket.data_bucket.bucket
}
}
depends_on = [aws_iam_role_policy_attachment.lambda_policy_attachment]
}
# Create Lambda event source mapping for Kinesis
resource "aws_lambda_event_source_mapping" "kinesis_lambda" {
event_source_arn = aws_kinesis_stream.data_stream.arn
function_name = aws_lambda_function.process_kinesis.arn
starting_position = "LATEST"
}