-
Notifications
You must be signed in to change notification settings - Fork 0
/
AWS_Lambda.tf
66 lines (60 loc) · 1.54 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
resource "aws_iam_role" "lambda_role" {
name = "madhatter_lambda_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "lambda.amazonaws.com"
}
}
]
})
}
# IAM Policy for Lambda
resource "aws_iam_policy" "lambda_policy" {
name = "madhatter_lambda_policy"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"logs:*",
"s3:*",
"kinesis:*",
"redshift:*",
"athena:*"
]
Effect = "Allow"
Resource = "*"
}
]
})
}
# Attach Policy to Role
resource "aws_iam_role_policy_attachment" "lambda_policy_attachment" {
role = aws_iam_role.lambda_role.name
policy_arn = aws_iam_policy.lambda_policy.arn
}
resource "aws_lambda_function" "process_data" {
function_name = "madhatter_process_data"
role = aws_iam_role.lambda_role.arn
handler = "index.handler"
runtime = "nodejs14.x"
source_code_hash = filebase64sha256("lambda_function.zip")
filename = "lambda_function.zip"
timeout = 30
environment {
variables = {
S3_BUCKET = aws_s3_bucket.data_lake.bucket
}
}
# Add Kinesis event source
}
resource "aws_lambda_event_source_mapping" "kinesis_lambda" {
event_source_arn = aws_kinesis_stream.data_stream.arn
function_name = aws_lambda_function.process_data.arn
starting_position = "LATEST"
}