'How to skip Azure function output binding when there is an error?
We are using a simple python azure function to forward a JSON payload to an event hub. We have configured the event hub as the function output binding. Our requirement is to verify an APIKEY that comes as part of the header and if the request header doesn't have the APIKEY or match with our APIKEY, we want to skip the function output trigger. How do we achieve this? The current code looks like this
import logging
import azure.functions as func
import json
def main(req: func.HttpRequest) -> str:
logging.info('Send an output)
try:
if req.headers.get("MYAPIKEY") == APIKEY:
body = req.get_json()
return json.dumps(body)
except :
func.HttpResponse("Function failed")
Solution 1:[1]
- Event hub output binding requires at least one output per function call.
- If you are using return value version rather than that try using
IAsyncCollector
output binding. - You can check this Github discussion where you can use function out method.
- Here is the other Gitbhub discussion with related issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | SaiSakethGuduru-MT |