Azure Functions, Serverless DB & VSCode

Published dateJanuary 28, 2020

I’ve been doing pro-bono work with HandsOn Hong Kong (HOHK) for a while and I was asked to help them integrate their website to Social Career. Social Career is launching a new volunteer opportunity aggregator, Volunteer Movement https://volunteermovement.hk/ on Jan 31st 2020, to help promote volunteerism to the people of Hong Kong. HOHK, being one of the largest volunteering platforms in HK was asked to join.

In order to connect HOHK to Social Career, I needed to develop an API that could be called by Social Career every night.

The Technology

To complete the integration, I chose to use Azure functions + Python, partly to learn Azure functions and partly because HOHK is entitled to $3,500 USD of sponsored Azure credits that from Microsoft for Nonprofits. I felt that functions would incur the least amount of costs for the API, since it only needs to be called a few hundred time per day within a ~30 minute period. I also chose the relatively new Serverless Database based on this usage pattern. Finally, I also created a Logic App to run a scheduled task to for database cleanup.

Azure Functions, Python and VSCode

Creating the API with VSCode was extremely smooth. Azure functions have great integration with VSCode, and you can deploy changes to the functions directly from the IDE. I’d readily work with this setup in the future if need be.

One downside to using Python is that you can’t edit the code directly inside of Azure. You have to edit it in VSCode and redeploy every time.

The documentation for Functions + Python is OK, enough to get you started.

Serverless Database

I ran into issues using the lowest tier Serverless Database, specifically with the cold start time. When I tested the code, everything was responding quickly, but when it was called after the DB had spun down, the database connection’s 10 second timeout period would fail. I needed to implement a loop to retry the initial database connection and sleep if it failed, to ensure that there was enough time for the database to wake up.

Response times to the API after wakeup are pretty long, anywhere from 5000-6000 ms. After that, response times were between 500-1000 ms.

Cost Breakdown

The costs of this solution are 99% taken up by the Serverless Database VCores. I’m estimating a cost of ~30 USD a month based on current usage.