I have a lambda function that links shopify to a different app via shopify webhook. The workflow is like so:
- A purchase is made on shopify
- Once the purchase has been successful, a webhook is triggered
- Lambda listens for this webhook, does some stuff, and sends some data to another app
I've noticed something really weird though. In the Log events, when I run a "test" from within lambda itself, the function is triggered only once. However when I send a test webhook trigger from shopify, one single log event will have multiple invocations of my index.js file!
Multiple things about this confuse me:
- Why is it being triggered multiple times at all?
- Why are multiple triggers being logged in the same log file and not separate log events?? If shopify attempted to send the trigger multiple times wouldn't it show as multiple separate log events?
- It seems like during the first log of the invocation, if I console log the event being sent from shopify it's a default placeholder object, the same as if I log a test event through Lambda, and looks like this:
{ key1: 'value1', key2: 'value2', key3: 'value3' }. But the following invocations within the same log then have the correct JSON object that is sent from Shopify with all the data I need about that particular test purchase.
Can anyone help clear this up for me please?
If I set up a really basic index.js for testing that simply logs the event, this is what a test log sent from within lambda itself would look like:
- START RequestID: blahblah Version: $LATEST
- INFO This is a console log to see if it prints:
- INFO { key1: 'value1', key2: 'value2', key3: 'value3' }
- Duration: 10ms
And if I send a test by triggering a shopify event this is what the log would look like:
- START RequestID: blahblah Version: $LATEST
- INFO This is a console log to see if it prints:
- INFO { key1: 'value1', key2: 'value2', key3: 'value3' }
- Duration: 10ms
- INFO This is a console log to see if it prints:
- INFO { version: '2.0', routeKey: 'blah blah this is a correct json object sent from shopify' }
- Duration: 10ms
- INFO This is a console log to see if it prints:
- INFO { version: '2.0', routeKey: 'blah blah this is a correct json object sent from shopify' }
- Duration: 10ms