Skip to content

Commit 727ab44

Browse files
committed
feat: updated template and statemachine with new function config. Added policies. Temp fix for testing centre URL.
1 parent 1805868 commit 727ab44

File tree

2 files changed

+47
-25
lines changed

2 files changed

+47
-25
lines changed

src/backend/state-machine.asl.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ States:
6060
Resource: "arn:aws:states:::sns:publish.waitForTaskToken"
6161
Parameters:
6262
TopicArn: '${NotificationTopic}'
63-
Message.$: "States.Format('{}/?IncidentId={}&ExamId={}&TaskToken={}', $.TestingCentreUrl, $.Payload.IncidentId, $.Payload.Exams[0].ExamId, $$.Task.Token)"
63+
Message.$: "States.Format('http://localhost:3000/?IncidentId={}&ExamId={}&TaskToken={}', $.Payload.IncidentId, $.Payload.Exams[0].ExamId, $$.Task.Token)"
6464
Next: Has student passed exam?
6565

6666
Has student passed exam?:
@@ -85,7 +85,7 @@ States:
8585
Resource: arn:aws:states:::lambda:invoke
8686
Parameters:
8787
Payload.$: $
88-
FunctionName: ${Take administrative actionFunctionArn}
88+
FunctionName: ${TakeAdministrativeActionFunctionArn}
8989
Retry:
9090
- ErrorEquals:
9191
- Lambda.ServiceException

src/backend/template.yaml

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ Parameters:
3333
Type: String
3434
Description: Student email (testing only)
3535

36-
StudentTestingCentreUrl:
37-
Default: "http://localhost:3000"
38-
Type: String
39-
Description: Endpoint for the Testing Centre website
40-
4136

4237
Conditions:
4338
IsProd: !Equals [!Ref Stage, Prod]
@@ -81,11 +76,14 @@ Resources:
8176
Type: AWS::Serverless::Function
8277
Properties:
8378
Description: Plagiarism - Schedules the Exam for the student to complete.
84-
CodeUri: ./ScheduleExamTask
85-
Handler: ScheduleExamTask::ScheduleExamTask.Function::FunctionHandler
79+
CodeUri: ./ScheduleExam
80+
Handler: ScheduleExam::ScheduleExam.Function::FunctionHandler
8681
Policies:
8782
- DynamoDBWritePolicy:
8883
TableName: !Ref PlagiarismIncidentsTable
84+
- DynamoDBReadPolicy:
85+
TableName: !Ref PlagiarismIncidentsTable
86+
8987

9088
# User defined log group for the ScheduleExamFunction
9189
ScheduleExamFunctionLogGroup:
@@ -103,11 +101,13 @@ Resources:
103101
Type: AWS::Serverless::Function
104102
Properties:
105103
Description: Plagiarism - Marks the incident as resolved.
106-
CodeUri: ./ResolveIncidentTask
107-
Handler: ResolveIncidentTask::ResolveIncidentTask.Function::FunctionHandler
104+
CodeUri: ./ResolveIncident
105+
Handler: ResolveIncident::ResolveIncident.Function::FunctionHandler
108106
Policies:
109107
- DynamoDBWritePolicy:
110108
TableName: !Ref PlagiarismIncidentsTable
109+
- DynamoDBReadPolicy:
110+
TableName: !Ref PlagiarismIncidentsTable
111111

112112
# User defined log group for the ResolveIncidentFunction
113113
ResolveIncidentFunctionLogGroup:
@@ -125,12 +125,14 @@ Resources:
125125
Type: AWS::Serverless::Function
126126
Properties:
127127
Description: Plagiarism - Send email to administrative staff to notify staff that the student has failed all tests and action needs to be taken.
128-
CodeUri: ./AdminActionTask/
129-
Handler: AdminActionTask::AdminActionTask.Function::FunctionHandler
128+
CodeUri: ./AdminAction/
129+
Handler: AdminAction::AdminAction.Function::FunctionHandler
130130
Policies:
131131
- DynamoDBWritePolicy:
132132
TableName: !Ref PlagiarismIncidentsTable
133-
133+
- DynamoDBReadPolicy:
134+
TableName: !Ref PlagiarismIncidentsTable
135+
134136
# User defined log group for the TakeAdministrativeActionFunction
135137
TakeAdministrativeActionFunctionLogGroup:
136138
Type: AWS::Logs::LogGroup
@@ -147,11 +149,19 @@ Resources:
147149
Type: AWS::Serverless::Function
148150
Properties:
149151
Description: Plagiarism - Saves the test results and invokes the callback to the SendExamNotification state in the Step Function
150-
CodeUri: ./SubmitExamTask
151-
Handler: SubmitExamTask::SubmitExamTask.Function::FunctionHandler
152+
CodeUri: ./SubmitExam
153+
Handler: SubmitExam::SubmitExam.Function::FunctionHandler
152154
Policies:
153155
- DynamoDBWritePolicy:
154156
TableName: !Ref PlagiarismIncidentsTable
157+
- DynamoDBReadPolicy:
158+
TableName: !Ref PlagiarismIncidentsTable
159+
- Statement:
160+
- Effect: Allow
161+
Action:
162+
- states:SendTaskSuccess
163+
- states:SendTaskFailure
164+
Resource: !Ref PlagiarismStateMachine
155165
Events:
156166
StepApi:
157167
Type: Api
@@ -176,6 +186,7 @@ Resources:
176186
Type: AWS::Serverless::Api
177187
DependsOn: PlagiarismApiGwAccountConfig
178188
Properties:
189+
Name: !Sub "Plagiarism-API-${Stage}"
179190
StageName: !Ref Stage
180191
EndpointConfiguration:
181192
Type: REGIONAL
@@ -232,12 +243,12 @@ Resources:
232243
ManagedPolicyArns:
233244
- arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs
234245

235-
# Step function
246+
# Step Function
236247
# More info about State Machine Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
237248
PlagiarismStateMachine:
238249
Type: "AWS::Serverless::StateMachine"
239250
Properties:
240-
Name: !Ref AWS::StackName
251+
Name: !Sub "PlagiarismStateMachine-${Stage}"
241252
DefinitionUri: state-machine.asl.yaml
242253
Tracing:
243254
Enabled: true
@@ -246,7 +257,6 @@ Resources:
246257
TakeAdministrativeActionFunctionArn: !GetAtt TakeAdministrativeActionFunction.Arn
247258
ResolveIncidentFunctionArn: !GetAtt ResolveIncidentFunction.Arn
248259
NotificationTopic: !Ref PlagiarismTopic
249-
TestingCentreUrl: !Ref StudentTestingCentreUrl
250260
IncidentsTable: !Ref PlagiarismIncidentsTable
251261
Policies:
252262
- LambdaInvokePolicy:
@@ -257,8 +267,10 @@ Resources:
257267
FunctionName: !Ref ResolveIncidentFunction
258268
- DynamoDBWritePolicy:
259269
TableName: !Ref PlagiarismIncidentsTable
270+
- DynamoDBReadPolicy:
271+
TableName: !Ref PlagiarismIncidentsTable
260272
- SNSPublishMessagePolicy:
261-
TopicName: !GetAtt PlagiarismTopic.TopicName
273+
TopicName: !GetAtt PlagiarismTopic.TopicName
262274
- Statement:
263275
- Effect: Allow
264276
Action:
@@ -285,7 +297,7 @@ Resources:
285297
UpdateReplacePolicy: Delete
286298
DeletionPolicy: Delete
287299
Properties:
288-
LogGroupName: !Sub "/aws/states/${AWS::StackName}-PlagiarismStateMachine"
300+
LogGroupName: !Sub "/aws/states/PlagiarismStateMachine-${Stage}"
289301
RetentionInDays: !FindInMap [LogsRetentionPeriodMap, !Ref Stage, Days]
290302

291303
# SNS Topic to use in Step Functions
@@ -306,13 +318,14 @@ Resources:
306318
UpdateReplacePolicy: Delete
307319
DeletionPolicy: Delete
308320
Properties:
309-
TableName: !Ref AWS::StackName
321+
TableName: !Sub "PlagiarismIncidents-${Stage}"
310322
PrimaryKey:
311323
Name: IncidentId
312324
Type: String
313325
ProvisionedThroughput:
314326
ReadCapacityUnits: 5
315327
WriteCapacityUnits: 5
328+
316329

317330
# IAM roles
318331
ApiGatewayStepFunctionsRole:
@@ -402,9 +415,14 @@ Resources:
402415
Resource:
403416
- "*"
404417
Outputs:
405-
StepFunctionsAPIUrl:
406-
Description: API URL
407-
Value: !Sub "https://${PlagiarismApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}"
418+
419+
ApiEndpointRegisterIncident:
420+
Description: API endpoint for registering an incident
421+
Value: !Sub "https://${PlagiarismApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}/incident"
422+
423+
ApiEndpointSubmitExamResults:
424+
Description: API endpoint for submitting exam results
425+
Value: !Sub "https://${PlagiarismApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}/exam"
408426

409427
StepFunctionsStateMachine:
410428
Description: Step Functions State Machine ARN
@@ -414,6 +432,10 @@ Outputs:
414432
Description: Schedule Exam Function ARN
415433
Value: !GetAtt ScheduleExamFunction.Arn
416434

435+
SubmitExamResultsFunctionArn:
436+
Description: Submit Exam Function Function ARN
437+
Value: !GetAtt SubmitExamResultsFunction.Arn
438+
417439
ResolveIncidentFunctionArn:
418440
Description: Resolve Incident Function ARN
419441
Value: !GetAtt ResolveIncidentFunction.Arn

0 commit comments

Comments
 (0)