# Amazon Rekognition Resources (used in Lab 01: Vision) # Creates Rekognition collections and custom labels projects. locals { enabled = var.enabled collection_name = var.collection_name != null ? var.collection_name : "${var.namespace}-${var.lab}-${var.stage}-${var.name}" project_name = var.project_name != null ? var.project_name : "${var.namespace}-${var.lab}-${var.stage}-${var.name}-project" } # Rekognition Collection for face indexing resource "aws_rekognition_collection" "this" { count = local.enabled && var.create_collection ? 1 : 0 collection_id = local.collection_name tags = merge(var.tags, { Name = local.collection_name Lab = var.lab }) } # Custom Labels Project (for custom object detection) resource "aws_rekognition_project" "this" { count = local.enabled && var.create_custom_labels_project ? 1 : 0 name = local.project_name # auto_update must be set for CONTENT_MODERATION projects and must NOT be # set for CUSTOM_LABELS projects. auto_update = var.project_feature == "CONTENT_MODERATION" ? var.auto_update : null # Feature can be CONTENT_MODERATION or CUSTOM_LABELS feature = var.project_feature } # SNS Topic for async operations notifications resource "aws_sns_topic" "rekognition" { count = local.enabled && var.create_sns_topic ? 1 : 0 name = "${local.collection_name}-notifications" tags = merge(var.tags, { Name = "${local.collection_name}-notifications" Lab = var.lab }) } # IAM Role for Rekognition to publish to SNS resource "aws_iam_role" "rekognition_sns" { count = local.enabled && var.create_sns_topic ? 1 : 0 name = "${local.collection_name}-rekognition-sns" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [ { Action = "sts:AssumeRole" Effect = "Allow" Principal = { Service = "rekognition.amazonaws.com" } } ] }) tags = merge(var.tags, { Name = "${local.collection_name}-rekognition-sns" Lab = var.lab }) } resource "aws_iam_role_policy" "rekognition_sns" { count = local.enabled && var.create_sns_topic ? 1 : 0 name = "${local.collection_name}-sns-publish" role = aws_iam_role.rekognition_sns[0].id policy = jsonencode({ Version = "2012-10-17" Statement = [ { Effect = "Allow" Action = "sns:Publish" Resource = aws_sns_topic.rekognition[0].arn } ] }) }