Hello Simon Stewart,
Thank you for posting your question in the Microsoft Q&A forum.
The intermittent HTTP 401 errors and vanishing function keys in your Azure Function App suggest underlying key management instability, potentially tied to the Consumption Plan's dynamic scaling or Linux/Python runtime quirks. While your authLevel="function" configuration is correct, the inconsistent key behavior points to:
- Key Synchronization Delays: The Linux Consumption Plan’s ephemeral containers may fail to propagate key updates immediately, causing temporary 401s until the new key syncs across instances.
- EventGrid Validation Quirks: EventGrid’s webhook validation ignores the code parameter in its initial handshake, requiring a publicly accessible endpoint (anonymous) for validation, followed by function-level auth for actual events.
- ZIP Deploy Cache Issues: Python functions on Linux may retain stale key references after deployment. Try restarting the Function App post-deployment.
Solutions you may try -
- Use Host Keys Instead: Replace code=my-function-key with code=my-host-key (found under App Keys), as host keys are more stable.
- Split Authentication: Temporarily set authLevel="anonymous" for EventGrid validation, then switch to function post-validation (despite the security trade-off).
- Check Logs: Enable Application Insights to trace 401s and key-related errors (Host.Function.APIKey).
- Migrate to Premium Plan: For production, avoid Consumption Plan key sync issues by upgrading.
If keys still disappear, recreate the Function App or raise a support ticket this may indicate a platform bug.
Some reference documentation may help:
https://learn.microsoft.com/en-us/azure/event-grid/end-point-validation-cloud-events-schema
If the above answer helped, please do not forget to "Accept Answer" as this may help other community members to refer the info if facing a similar issue. Your contribution to the Microsoft Q&A community is highly appreciated.