I have an Azure Function triggered by Event Grid Events. Event Grid Events are created only when a blob is uploaded to a Storage Account.
This is now deployed and working well although for some reason, the Function keeps getting triggered by the same event even though it successfully processed?
Example:
Today I review the logs, and the function has continued to execute!
Error: "Blob does not exist"
I deleted the blob after last test yesterday. Why is the Event Grid still firing?
Code snippet:
def main(event: func.EventGridEvent):
result = json.dumps({
'id' : event.id,
'data' : event.get_json(),
'topic' : event.topic,
'subject' : event.subject,
'event_type' : event.event_type
})
logging.info('EventGrid trigger processing an event: %s', result)
credential = DefaultAzureCredential()
download_start_time = datetime.datetime.now()
logging.info(f'######## Starting downloading blob from storage at ' + str(download_start_time) + ' ########')
# =============================
# Download blob from storage container:
# =============================
blob_client = BlobClient.from_blob_url(event.get_json()["url"], credential)
blob_data = blob_client.download_blob().readall()
blob_byte_stream = io.BytesIO(blob_data)
EDIT 1: This is still happening, this time a bit different.
- Now, the EventGrid keeps firing after SUCCESSFULLY passing messages and the Function running
How do I debug this?
I finally figured out what the issue was...using the
BlobClient.from_blob_url
method worked fine when testing blob uploads using Azure Storage Explorer. But when using Azure Data Factory, a different API is used and thedata.url
property in the EventGrid message is not the actual blob url (containeddfs
instead ofblob
).Oddly enough, soon after I brought this issue up to support team, a new
blobUrl
property was added to EventGriddata
object.In my code, I simply changed "url" to "blobUrl" and the method succeeded. (I also improved the error handling of the Python code to accommodate such errors in the future.)
Documented EventGrid message (as of 12/10/2020):
blobUrl
propertyActual EventGrid message coming through now:
blobUrl
has been added to the schemaAnother caveat here...notice the
Content-Length
in the message aboveCreateFile
API is not the actual message which indicates the blob has been created.FlushWithClose
API isThere is a note in the docs about this. So I also had to setup an EventGrid Advanced Filter which only triggers when
FlushWithClose
events are generated (!)