Prerequisites
Step 1: Scaffold a serverless function
You can do this directly through AWS, but we prefer to use Serverless which creates a helpful layer of abstraction on top of Lambda. First install their framework:AWS - Node.js - HTTP API
as this tutorial will be using Node.js.
If you cd into the directory that was created, you should see an index.js
file which is where we will be writing our code.
It will look something like this:
Step 2: Create our webhook inside Dynamic
We need to create a webhook inside Dynamic that will send a POST request to our serverless function whenever a new user signs up. To do this we can visit the webhooks section of the dashboard and click âCreate Webhookâ. It will ask you for a URL and to mark the events you want to listen to. For now we can use a fake URL, which we can generate from webhook.site. This will give us a URL that we can use to test our webhook, and will show us the data that is being sent to it. For the events, you should make sure user.created is selected, and thatâs it! Save away and a test event will be sent to your URL.Step 3: Adapt the function to receive a Dynamic webhook event
Letâs say in this instance We are most interested in the user object, as this is returned by the user.created event. You can find the full list of events here. As youâll see from the event reference, the only required field on the object is the ID, so if you want to collect more information youâll need to make sure youâre doing Info Capture on signup.In this tutorial we will assume we are using email signup with embedded
wallets, so weâll always have email available on the user object at time of
signup
data
field, and itâs inside this field that the user object will be present. Hereâs how we can use the email inside the function: