简体   繁体   中英

Start/Stop Azure Function App using python

有没有一种方法可以通过将参数传递给函数的http触发url来使用python编程来启动/停止a​​zure函数应用

If I understand the question correctly, you want to access query parameter in your function file. Here is the binding for a sample azure function:-

 { "scriptFile": "__init__.py", "bindings": [ { "authLevel": "function", "type": "httpTrigger", "direction": "in", "name": "req", "methods": [ "get", "post" ] }, { "type": "http", "direction": "out", "name": "$return" } ] } 

and suppose this is the function

 def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') name = req.params.get('name') if not name: try: req_body = req.get_json() except ValueError: pass else: name = req_body.get('name') if name: return func.HttpResponse(f"Hello {name}!") else: return func.HttpResponse( "Please pass a name on the query string or in the request body", status_code=400 ) 

Above sample function accepts an http POST request, and requires your request body to be a JSON payload with a "name" property.

To access URL query parameters, we make them available to you as distinct environment variables. For example, if you send query parameter "foo", you can access it via os.environ['req_query_foo'].

and then based on the query param , you can start and stop the function .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM