diff --git a/services/terraform/modules/shared/dynamodb.tf b/services/terraform/modules/shared/dynamodb.tf --- a/services/terraform/modules/shared/dynamodb.tf +++ b/services/terraform/modules/shared/dynamodb.tf @@ -243,9 +243,11 @@ } resource "aws_dynamodb_table" "identity-reserved-usernames" { - name = "identity-reserved-usernames" - hash_key = "username" - billing_mode = "PAY_PER_REQUEST" + name = "identity-reserved-usernames" + hash_key = "username" + billing_mode = "PAY_PER_REQUEST" + stream_enabled = true + stream_view_type = "NEW_AND_OLD_IMAGES" attribute { name = "username" diff --git a/services/terraform/modules/shared/outputs.tf b/services/terraform/modules/shared/outputs.tf --- a/services/terraform/modules/shared/outputs.tf +++ b/services/terraform/modules/shared/outputs.tf @@ -5,6 +5,7 @@ aws_dynamodb_table.reports-service-reports, aws_dynamodb_table.tunnelbroker-undelivered-messages, aws_dynamodb_table.identity-users, + aws_dynamodb_table.identity-reserved-usernames, ] } diff --git a/services/terraform/modules/shared/search_index_lambda.tf b/services/terraform/modules/shared/search_index_lambda.tf --- a/services/terraform/modules/shared/search_index_lambda.tf +++ b/services/terraform/modules/shared/search_index_lambda.tf @@ -41,6 +41,12 @@ starting_position = "LATEST" } +resource "aws_lambda_event_source_mapping" "identity_reserved_usernames_trigger" { + event_source_arn = aws_dynamodb_table.identity-reserved-usernames.stream_arn + function_name = aws_lambda_function.search_index_lambda.arn + starting_position = "LATEST" +} + resource "aws_security_group" "search_index_lambda" { name = "search_index_lambda_sg" vpc_id = var.vpc_id diff --git a/services/terraform/remote/aws_iam.tf b/services/terraform/remote/aws_iam.tf --- a/services/terraform/remote/aws_iam.tf +++ b/services/terraform/remote/aws_iam.tf @@ -231,9 +231,10 @@ "dynamodb:ListStreams", ] resources = [ - module.shared.dynamodb_tables["identity-users"].arn, module.shared.dynamodb_tables["identity-users"].stream_arn, "${module.shared.dynamodb_tables["identity-users"].arn}/stream/*", + module.shared.dynamodb_tables["identity-reserved-usernames"].stream_arn, + "${module.shared.dynamodb_tables["identity-reserved-usernames"].arn}/stream/*", ] } }