How to get Azure Function name from within a function using C# script (csx)
Asked Answered
L

1

5

My goal is to provide a code snippet to customers. One file will contain customer's business logic, another file will provide its handling. For the latter I need to have a name of a function [would like to avoid asking customers to enter this information manually].

I searched around but could not figure out. Essentially I need this:

enter image description here

Lamoreaux answered 16/4, 2021 at 21:7 Comment(0)
B
15

The ExecutionContext class has a property FunctionName (docs)

You can inject the class like this:

[FunctionName("HttpTriggered")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
     HttpRequest req, 
     ExecutionContext executionContext)
{
     var name = executionContext.FunctionName;
     ...
}

The output will be

HttpTriggered

Bos answered 16/4, 2021 at 21:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.