-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_function.tf
70 lines (60 loc) · 1.86 KB
/
search_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
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
data "aws_caller_identity" "current" {}
data "archive_file" "search_function" {
type = "zip"
output_path = "${path.module}/search_function.zip"
source {
content = file("src/search_function.py")
filename = "search_function.py"
}
source {
content = file("src/rekognition_image.py")
filename = "rekognition_image.py"
}
}
resource "aws_lambda_function" "search_function" {
function_name = "personnel-recognition-searcher"
role = aws_iam_role.search_function.arn
publish = true
runtime = "python3.8"
handler = "search_function.lambda_handler"
memory_size = 512
timeout = 60
filename = data.archive_file.search_function.output_path
source_code_hash = data.archive_file.search_function.output_base64sha256
environment {
variables = {
MAX_FACES_COUNT = var.max_faces_count
FACE_DETECT_THRESHOLD = var.face_detect_threshold
COLLECTION_ID = var.collection_id
TABLE_ID = local.table_name
}
}
}
data "aws_iam_policy_document" "search_role_policy" {
version = "2012-10-17"
statement {
effect = "Allow"
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"rekognition:DescribeCollection",
"rekognition:SearchFacesByImage",
"dynamodb:GetItem",
]
resources = [
"arn:aws:logs:*:*:*",
"arn:aws:rekognition:*:*:collection/${var.collection_id}",
"arn:aws:dynamodb:*:*:table/${local.table_name}"
]
}
}
resource "aws_iam_role" "search_function" {
name = "faces-search-function-lambda-role"
assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json
}
resource "aws_iam_role_policy" "search_function" {
name = "cloudwatch_search"
role = aws_iam_role.search_function.id
policy = data.aws_iam_policy_document.search_role_policy.json
}