-
Notifications
You must be signed in to change notification settings - Fork 9
/
scanner-function.tf
40 lines (33 loc) · 1.13 KB
/
scanner-function.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
resource "aws_lambda_function" "antivirus-scanner" {
function_name = "bucket-antivirus-scanner"
timeout = 300
memory_size = 1024
runtime = "python2.7"
handler = "scan.lambda_handler"
role = aws_iam_role.antivirus-scanner-role.arn
s3_bucket = aws_s3_bucket.antivirus-code.bucket
s3_key = aws_s3_bucket_object.antivirus-code.key
environment {
variables = merge(
{
AV_DEFINITION_S3_BUCKET = aws_s3_bucket.antivirus-definitions.bucket
},
var.scanner-environment-variables
)
}
}
resource "aws_lambda_permission" "trigger-by-s3" {
count = length(var.buckets-to-scan)
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.antivirus-scanner.function_name
principal = "s3.amazonaws.com"
source_arn = "arn:aws:s3:::${var.buckets-to-scan[count.index]}"
}
resource "aws_s3_bucket_notification" "staging" {
count = length(var.buckets-to-scan)
bucket = var.buckets-to-scan[count.index]
lambda_function {
lambda_function_arn = aws_lambda_function.antivirus-scanner.arn
events = ["s3:ObjectCreated:*"]
}
}