I have created a function triggered by Azure Cosmos DB by following https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-cosmos-db-triggered-function which is working.
Upon seeing logs, I am unable to identify if this trigger is for INSERT or UPDATE. I know that in AWS, when you add lambda as the dynamo trigger, you could identify that easily. You can even see what was original record vs updated one (for update)
Question:
- How to identify INSERT vs UPDATE vs DELETE action? I am new to Azure, so it is possible that I am missing something in my function code.
Function Code:
module.exports = async function (context, documents) {
context.log('1');
if (!!documents && documents.length > 0) {
context.log('Document Id: ', documents[0].id); <-- SHOWS ID OF THE RECORD
context.log('Document[0]', documents[0]); <-- ENTIRE RECORD
context.log('Documents', documents); <-- ALL RECORDS
}
}
context object from above:
{
invocationId: '3ee0136e-d005-4517-a11e-c43ec9ca7c67',
traceContext: {
traceparent: '00-4938136b13476845524c7ae5059d84f3-badfbc56b5ef0067-00',
tracestate: '',
attributes: {
OperationName: 'CosmosTrigger1'
}
},
executionContext: {
invocationId: '3ee0136e-d005-4517-a11e-c43ec9ca7c67',
functionName: 'CosmosTrigger1',
functionDirectory: 'C:\\home\\site\\wwwroot\\CosmosTrigger1',
retryContext: null
},
bindings: {
documents: [
[
Object
]
]
},
log: [
Function(anonymous)
]{
error: [
Function: error
],
warn: [
Function: warn
],
info: [
Function: info
],
verbose: [
Function: verbose
]
},
bindingData: {
invocationId: '3ee0136e-d005-4517-a11e-c43ec9ca7c67'
},
bindingDefinitions: [
{
name: 'documents',
type: 'cosmosDBTrigger',
direction: 'in'
}
],
done: [
Function(anonymous)
]
}