|
8 | 8 | Stack, |
9 | 9 | aws_sqs as sqs, |
10 | 10 | aws_dynamodb as dynamodb, |
| 11 | + aws_apigateway as apigateway, |
11 | 12 | aws_iam as iam, |
12 | 13 | aws_lambda as _lambda, |
13 | 14 | CfnOutput as Output |
@@ -71,6 +72,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: |
71 | 72 | ("ListPublicQuizzesFunction", "configurations/list_quizzes_policy.json", "ListQuizzesRole", "lambdas/list_quizzes"), |
72 | 73 | ("RetryQuizzesWritesFunction","configurations/retry_quizzes_writes_policy.json", "RetryQuizzesWritesRole", "lambdas/retry_quizzes_writes"), |
73 | 74 | ] |
| 75 | + functions = {} |
74 | 76 |
|
75 | 77 | for function_info in functions_and_roles: |
76 | 78 |
|
@@ -106,15 +108,31 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: |
106 | 108 | role=role, |
107 | 109 | timeout=aws_cdk.Duration.seconds(30), |
108 | 110 | ) |
| 111 | + functions[function_name] = current_function |
| 112 | + |
| 113 | + submission_queue.grant_consume_messages(functions["ScoringFunction"]) |
| 114 | + _lambda.EventSourceMapping( |
| 115 | + self, |
| 116 | + "ScoringFunctionSubscription", |
| 117 | + target=functions["ScoringFunction"], |
| 118 | + event_source_arn=submission_queue.queue_arn, |
| 119 | + ) |
| 120 | + |
| 121 | + # create rest api |
| 122 | + rest_api = apigateway.RestApi(self, "QuizAPI") |
| 123 | + endpoints = [ |
| 124 | + ("getquiz", "GET", "GetQuizFunction"), |
| 125 | + ("createquiz", "POST", "CreateQuizFunction"), |
| 126 | + ("submitquiz", "POST", "SubmitQuizFunction"), |
| 127 | + ("getsubmission", "GET", "GetSubmissionFunction"), |
| 128 | + ("getleaderboard", "GET", "GetLeaderboardFunction"), |
| 129 | + ("listquizzes", "GET", "ListPublicQuizzesFunction"), |
| 130 | + ] |
| 131 | + for path_part, http_method, function_name in endpoints: |
| 132 | + resource = rest_api.root.add_resource(path_part) |
| 133 | + integration = apigateway.LambdaIntegration(functions[function_name], proxy=True) |
| 134 | + resource.add_method(http_method, integration=integration) |
109 | 135 |
|
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 | 136 |
|
119 | 137 |
|
120 | 138 | @staticmethod |
|
0 commit comments