Submit Database information to AWS Lambda function

Submit Database information to AWS Lambda function

by ALEXANDER WILKE -
Number of replies: 3

Hello, I'm new to moodle development.

Currently I'm tried to integrate a way to run a AWS Lambda function when a student submits their answers from a quiz that they take. Basically, I'm trying to get the users student ID and question ID from moodle, and send this to AWS using their LamdaAPI through a POST request.


Is there any way to do this exactly, or do I need to create my own plugin? 

Average of ratings: -
In reply to ALEXANDER WILKE

Re: Submit Database information to AWS Lambda function

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
What is this AWS lambda going to do? AWS lambda is just a techology, obviously there is some purpose you are trying to achieve, if you tell us that purpose, we can probably give better advice.
Average of ratings: Useful (1)
In reply to ALEXANDER WILKE

Re: Submit Database information to AWS Lambda function

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi Alexander.

This is just a rough how you would go about this. The details, eg the exact Moodle event, you will need to investigate.
If you want to do this without writing a plugin you can use one of these 'trigger' plugins:
https://github.com/justinhunt/moodle-local_trigger
https://moodle.org/plugins/local_webhooks
https://moodle.org/plugins/tool_trigger

To post a request to a webhook published by:
https://zapier.com

Basically you will pipe the event:
mod_quiz_get_attempt_data
(See [your/moodle/server/url]/admin/webservice/documentation.php )

via the 'trigger' plugin to a Zapier - webhook[trigger] 
which will connect it to Zapier - Lambda [action]
Average of ratings: Useful (1)
In reply to Justin Hunt

Re: Submit Database information to AWS Lambda function

by ALEXANDER WILKE -
Thanks guys for the help! Looking back now, I had no idea at all what I was doing haha.
After the last week, I've been doing some really deep diving into moodles apis and some of the core modules. I can say that there's quite a bit to learn!

I managed to get a callback working by creating my own local plugin, which listens for the quiz_submission event from the quiz module. It works, and triggers successfully!

However, now I would like to get an audio recording file from the moodle database which is saved in the 'essay' type question from the quiz module.
I've just been learning a lot about how all the pieces work together, and it's quite confusing. Basically, I'm trying to use the File API now to get a URL which I will send to my lambda function running on AWS. I need to get the file from moodles database to lamda, so I'm using the python requests module to download it from the moodle generate link using the pluginfile.php script.

I'm just having a big of trouble right now getting the right URL for the file.
I want to only get files which have been 'unmarked'. I'm using the question_attempt_steps table to determine the question state.
I also know that I need the context ID, so somehow I need to get this. I already know which file_area and component name I need use.

Any advice on what other info I might need, and how I could get it?