Reputation: 468
I'm new using Azure, and I don't know if what I'm trying to do is possible
I have a Synthetic Graphql API defined in my Azure API Management Service. There I have my queries and mutations, till this point so far so good.
Now, imagine that I have this query in my graphql schema:
Query {
myQuery(userId: UUID!): [Cars]
}
which is going to resolve all cars owned by the user. This query is handled by an Azure Function, which is a HttpTrigger implemented as an Isolated Azure Function because we want to use .Net 8.
Our problem is that this function must be started manually before running the query and the same thing to stop it after the call finishes. What we want is this the azure function starts/stop automatically to save money
Is there any way to do that? Cause even when I created the Azure Function as Consumptio (Serveless), I don't see that it works in that way
Any idea?
PD: I created my Azure Function with this config:
And the HttpTrigger was created in Jetbrain Rider and then deployed yo Azure. I'm not using Visual Studio
Upvotes: 0
Views: 407
Reputation: 361
At first, Azure functions serverless is the best fit for your scenario and the HTTP trigger is one of the triggers that is supported by Azure functions. please find more details here
Secondly, the serverless model is scalable with a cold start functionality, so the first request might take some time to start the required computing then the rest will work normally.
For cost, the Serverless model relies on the number of executions and the the execution time. so combining that with autoscaling means only paying for your consumption regardless of the way of triggering the function. please find more details here
For the triggering, the HTTP trigger might need to be created in a proper way to be able to trigger the function. here is an example
[Function("HttpTrigger1")]
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post",
Route = "products/{category:alpha}/{id:int?}")] HttpRequestData req, string category, int? id,
FunctionContext executionContext)
{
var logger = executionContext.GetLogger("HttpTrigger1");
logger.LogInformation("C# HTTP trigger function processed a request.");
var message = String.Format($"Category: {category}, ID: {id}");
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.WriteString(message);
return response;
}
Here you define an Azure Function that will be triggered when an HTTP GET or POST request is made to the URL pattern specified in the Route property. When the Azure Function host receives a request at the specified route that matches the defined HTTP methods (get, post), it will execute the Run method of this function, passing in the parts of the URL that correspond to the category and id route parameters.
For the route, here is an example:
Route = "carrental/{customerID:int}/rent"
This means that the function will be triggered by a POST or GET request to a URL like /api/carrental/user/rent, where "user" is an example of a customerID
The URL to call the function could be like that
https://<APP_NAME>.azurewebsites.net/api/carrental/{customerName}/rent
Hope this help
Upvotes: 0