@@ -22,6 +22,14 @@ Parameters:
2222    Default : false 
2323    Type : String 
2424    AllowedValues : [true, false] 
25+   SqsLambdaTimeout :
26+     Description : How long the SQS lambda is permitted to run (in seconds) 
27+     Default : 300 
28+     Type : Number 
29+   SqsMessageTimeout :
30+     Description : MessageVisibilityTimeout for the SQS Lambda queue (should be at least 6xSqsLambdaTimeout) 
31+     Default : 1800 
32+     Type : Number 
2533
2634Conditions :
2735  IsProd : !Equals [!Ref RunEnvironment, 'prod'] 
@@ -74,6 +82,7 @@ Resources:
7482        RunEnvironment : !Ref RunEnvironment 
7583        LambdaFunctionName : !Sub ${ApplicationPrefix}-lambda 
7684        SesEmailDomain : !FindInMap [General, !Ref RunEnvironment, SesDomain] 
85+         SqsQueueArn : !GetAtt AppSQSQueues.Outputs.MainQueueArn 
7786
7887  AppLogGroups :
7988    Type : AWS::Serverless::Application 
@@ -83,6 +92,14 @@ Resources:
8392        LambdaFunctionName : !Sub ${ApplicationPrefix}-lambda 
8493        LogRetentionDays : !FindInMap [General, !Ref RunEnvironment, LogRetentionDays] 
8594
95+   AppSQSQueues :
96+     Type : AWS::Serverless::Application 
97+     Properties :
98+       Location : ./sqs.yml 
99+       Parameters :
100+         QueueName : !Sub ${ApplicationPrefix}-sqs 
101+         MessageTimeout : !Ref SqsMessageTimeout 
102+ 
86103  IcalDomainProxy :
87104    Type : AWS::Serverless::Application 
88105    Properties :
@@ -149,6 +166,40 @@ Resources:
149166            Path : /{proxy+} 
150167            Method : ANY 
151168
169+   AppSqsLambdaFunction :
170+     Type : AWS::Serverless::Function 
171+     DependsOn :
172+       - AppLogGroups 
173+     Properties :
174+       Architectures : [arm64] 
175+       CodeUri : ../dist/sqsConsumer 
176+       AutoPublishAlias : live 
177+       Runtime : nodejs22.x 
178+       Description : !Sub "${ApplicationFriendlyName} SQS Lambda" 
179+       FunctionName : !Sub ${ApplicationPrefix}-sqs-lambda 
180+       Handler : index.handler 
181+       MemorySize : 512 
182+       Role : !GetAtt AppSecurityRoles.Outputs.MainFunctionRoleArn 
183+       Timeout : !Ref SqsLambdaTimeout 
184+       LoggingConfig :
185+         LogGroup : !Sub /aws/lambda/${ApplicationPrefix}-lambda 
186+       Environment :
187+         Variables :
188+           RunEnvironment : !Ref RunEnvironment 
189+       VpcConfig :
190+         Ipv6AllowedForDualStack : !If [ShouldAttachVpc, True, !Ref AWS::NoValue] 
191+         SecurityGroupIds : !If [ShouldAttachVpc, !FindInMap [EnvironmentToCidr, !Ref RunEnvironment, SecurityGroupIds], !Ref AWS::NoValue] 
192+         SubnetIds : !If [ShouldAttachVpc, !FindInMap [EnvironmentToCidr, !Ref RunEnvironment, SubnetIds], !Ref AWS::NoValue] 
193+ 
194+   SQSLambdaEventMapping :
195+     Type : AWS::Lambda::EventSourceMapping 
196+     Properties :
197+       BatchSize : 5 
198+       EventSourceArn : !GetAtt AppSQSQueues.Outputs.MainQueueArn 
199+       FunctionName : !Sub ${ApplicationPrefix}-sqs-lambda 
200+       FunctionResponseTypes :
201+         - ReportBatchItemFailures 
202+ 
152203  IamGroupRolesTable :
153204    Type : ' AWS::DynamoDB::Table' 
154205    DeletionPolicy : " Retain" 
@@ -348,6 +399,23 @@ Resources:
348399        - Name : ' ApiName' 
349400          Value : !Sub ${ApplicationPrefix}-gateway 
350401
402+ 
403+   AppDLQMessagesAlarm :
404+     Type : ' AWS::CloudWatch::Alarm' 
405+     Condition : IsProd 
406+     Properties :
407+       AlarmName : !Sub ${ApplicationPrefix}-sqs-dlq 
408+       AlarmDescription : ' Items are present in the application DLQ, meaning some messages failed to process.' 
409+       Namespace : ' AWS/SQS' 
410+       MetricName : ' ApproximateNumberOfMessagesVisible' 
411+       Statistic : ' Sum' 
412+       Period : ' 60' 
413+       EvaluationPeriods : ' 1' 
414+       ComparisonOperator : ' GreaterThanThreshold' 
415+       Threshold : ' 0' 
416+       AlarmActions :
417+         - !Ref  AlertSNSArn 
418+ 
351419  APILambdaPermission :
352420    Type : AWS::Lambda::Permission 
353421    Properties :
0 commit comments