I have a javascript Azure function on a consumption plan that is triggered by an HTTP request. This Azure function makes an HTTP request itself to a 3rd party API.
The problem I am facing is that the Azure function is sometimes getting called dozens/hundreds of times within a few seconds, and so the outgoing API calls to the 3rd party start returning 429 (too many requests).
I want to try and limit the azure function to only handle one request at a time. To do so I have added:
maxConcurrentRequests: 1
WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT = 1
to host.json and function configuration respectively
I have also added the following function that I await call before each external API call to try and slow down the requests
function RunAfterOneSec() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 1500);
});
}
However, despite these efforts, I am still getting 429 responses from the API rate limited (limited to 60 requests/min)
Any help would be greatly appreciated.
Cheers.