@@ -60,6 +60,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
6060 write_capacity = 5 ,
6161 )
6262
63+ submission_queue = sqs .Queue (self , "QuizSubmissionQueue" , queue_name = "QuizSubmissionQueue" )
6364 functions_and_roles = [
6465 ("CreateQuizFunction" ,"configurations/create_quiz_policy.json" ,"CreateQuizRole" , "lambdas/get_quiz" ),
6566 ("GetQuizFunction" ,"configurations/get_quiz_policy.json" ,"GetQuizRole" , "lambdas/get_quiz" ),
@@ -95,7 +96,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
9596 # Attach the policy to the role
9697 role .add_managed_policy (policy )
9798
98- _lambda .Function (
99+ current_function = _lambda .Function (
99100 self ,
100101 f"{ function_name } LambdaFunction" ,
101102 function_name = function_name ,
@@ -106,7 +107,15 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
106107 timeout = aws_cdk .Duration .seconds (30 ),
107108 )
108109
109- sqs .Queue (self , "QuizSubmissionQueue" , queue_name = "QuizSubmissionQueue" )
110+ if function_name == "ScoringFunction" :
111+ submission_queue .grant_consume_messages (current_function )
112+ _lambda .EventSourceMapping (
113+ self ,
114+ "ScoringFunctionSubscription" ,
115+ target = current_function ,
116+ event_source_arn = submission_queue .queue_arn ,
117+ )
118+
110119
111120 @staticmethod
112121 def read_policy_file (file_path : str ) -> dict :
0 commit comments