|
| 1 | +# Setup tables |
| 2 | + |
| 3 | +1. Create the table using the console: |
| 4 | + |
| 5 | +``` |
| 6 | +Table name: notes |
| 7 | +
|
| 8 | +Columns: |
| 9 | +id: Integer auto-increment |
| 10 | +note: Text |
| 11 | +
|
| 12 | +Table name: note_revision |
| 13 | +
|
| 14 | +Columns: |
| 15 | +id: Integer auto-increment |
| 16 | +note: Text |
| 17 | +note_id: Integer (foreign key to notes.id) |
| 18 | +update_at: Timestamp, default `now()` |
| 19 | +
|
| 20 | +``` |
| 21 | + |
| 22 | +# Setup AWS Lambda |
| 23 | + |
| 24 | +Create a lambda function in AWS. This will be our webhook. |
| 25 | + |
| 26 | +1. Create a function. |
| 27 | +1. Select Ruby 2.5 as the runtime. |
| 28 | +1. Select "Author from scratch". |
| 29 | +1. Select "handler" as the function name. |
| 30 | +1. Press "Create function". |
| 31 | +1. Add API gateway as a trigger (in this example you can use Open as the security option). |
| 32 | +1. Add an API to API gateway. |
| 33 | +1. Add the code in `lambda_function.rb` to the lambda function editor. The handler function of your lambda will be the lambda_handler. |
| 34 | +1. Add the following enviroment variables in your lambda config: |
| 35 | + 1. `ACCESS_KEY`: this is the access key you configured when you setup HGE (`HASURA_GRAPHQL_ADMIN_SECRET` env variable). |
| 36 | + 1. `HGE_ENDPOINT`: the URL on which you HGE instance is running. |
| 37 | + |
| 38 | +# Add the trigger in Hasura GraphQL |
| 39 | + |
| 40 | +1. In events tab, add a trigger |
| 41 | +1. Select the "notes" table and the update trigger. |
| 42 | +1. Paste the API endpoint of your AWS lambda as the webhook. |
| 43 | + |
| 44 | +# Test your integration |
| 45 | + |
| 46 | +1. Create a note. |
| 47 | +1. Change the contents of the note. |
| 48 | +1. Select all note revisions, previous note value should be visible. |
| 49 | +1. Check the logs (in the Events tab) to see what is going on. |
0 commit comments