@@ -179,13 +179,24 @@ resource "aws_iam_policy" "filenameprocessor_lambda_sqs_policy" {
179179
180180 policy = jsonencode ({
181181 Version = " 2012-10-17" ,
182- Statement = [{
183- Effect = " Allow" ,
184- Action = [
185- " sqs:SendMessage"
186- ],
187- Resource = aws_sqs_queue.supplier_fifo_queue.arn
188- }]
182+ Statement = [
183+ {
184+ Effect = " Allow" ,
185+ Action = [
186+ " sqs:SendMessage"
187+ ],
188+ Resource = aws_sqs_queue.supplier_fifo_queue.arn
189+ },
190+ {
191+ Effect = " Allow" ,
192+ Action = [
193+ " sqs:ReceiveMessage" ,
194+ " sqs:DeleteMessage" ,
195+ " sqs:GetQueueAttributes"
196+ ],
197+ Resource = aws_sqs_queue.batch_file_created_queue.arn
198+ }
199+ ]
189200 })
190201}
191202
@@ -266,6 +277,7 @@ resource "aws_iam_role_policy_attachment" "filenameprocessor_lambda_dynamo_acces
266277 role = aws_iam_role. filenameprocessor_lambda_exec_role . name
267278 policy_arn = aws_iam_policy. filenameprocessor_dynamo_access_policy . arn
268279}
280+
269281# Lambda Function with Security Group and VPC.
270282resource "aws_lambda_function" "file_processor_lambda" {
271283 function_name = " ${ local . short_prefix } -filenameproc_lambda"
@@ -304,24 +316,11 @@ resource "aws_lambda_function" "file_processor_lambda" {
304316
305317}
306318
307-
308- # Permission for S3 to invoke Lambda function
309- resource "aws_lambda_permission" "s3_invoke_permission" {
310- statement_id = " AllowExecutionFromS3"
311- action = " lambda:InvokeFunction"
312- function_name = aws_lambda_function. file_processor_lambda . function_name
313- principal = " s3.amazonaws.com"
314- source_arn = aws_s3_bucket. batch_data_source_bucket . arn
315- }
316-
317- # S3 Bucket notification to trigger Lambda function
318- resource "aws_s3_bucket_notification" "datasources_lambda_notification" {
319- bucket = aws_s3_bucket. batch_data_source_bucket . bucket
320-
321- lambda_function {
322- lambda_function_arn = aws_lambda_function. file_processor_lambda . arn
323- events = [" s3:ObjectCreated:*" ]
324- }
319+ resource "aws_lambda_event_source_mapping" "batch_file_created_sqs_to_lambda" {
320+ event_source_arn = aws_sqs_queue. batch_file_created_queue . arn
321+ function_name = aws_lambda_function. file_processor_lambda . arn
322+ batch_size = 1
323+ enabled = true
325324}
326325
327326resource "aws_cloudwatch_log_group" "file_name_processor_log_group" {
0 commit comments