.. | |||
README.md | Loading last commit info... | ||
lambda_function.rb |
README.md
Setup tables
- Create the table using the console:
Table name: notes
Columns:
id: Integer auto-increment
note: Text
Table name: note_revision
Columns:
id: Integer auto-increment
note: Text
note_id: Integer (foreign key to notes.id)
update_at: Timestamp, default `now()`
Setup AWS Lambda
Create a lambda function in AWS. This will be our webhook.
- Create a function.
- Select Ruby 2.5 as the runtime.
- Select "Author from scratch".
- Select "handler" as the function name.
- Press "Create function".
- Add API gateway as a trigger (in this example you can use Open as the security option).
- Add an API to API gateway.
- Add the code in
lambda_function.rb
to the lambda function editor. The handler function of your lambda will be the lambda_handler. - Add the following enviroment variables in your lambda config:
ACCESS_KEY
: this is the access key you configured when you setup HGE (HASURA_GRAPHQL_ADMIN_SECRET
env variable).HGE_ENDPOINT
: the URL on which you HGE instance is running.
Add the trigger in Hasura GraphQL
- In events tab, add a trigger
- Select the "notes" table and the update trigger.
- Paste the API endpoint of your AWS lambda as the webhook.
Test your integration
- Create a note.
- Change the contents of the note.
- Select all note revisions, previous note value should be visible.
- Check the logs (in the Events tab) to see what is going on.