Azure Functions:
Python HTTP Example Code

The second step in my cloud journey is to discover how to use ‘serverless’ computing resources. New technologies such as AWS Lambda and Azure Functions make it easy to run arbitrary code across a scalable VM workforce without having to provision or manage those servers yourself.

This week I’ve picked Azure Functions to play with. And because I’m a Python fan – I decided to try and write a function in Python with HTTP triggers and responses. The end game in my mind is to create a microservice-style API built upon Azure Functions.

This wasn’t quite as simple as I’d expected, but once I worked out the concepts for data input and output (hint: environmental variables) it got a lot easier. It was one of those things where I’m pretty sure not many other people have walked the same path. There aren’t really any examples I could fine online of people doing this in Python (but the docs are great for Node.js and C#). Thankfully, my quest was made much easier by Christopher Anderson (the Azure Functions Product Manager himself!!) who made himself available via Twitter.

For those of you who are looking to achieve something similar, I’ve created a helper class and example code and put it on GitHub. Check it out.

This sample code will allow you to do the following:

  • Receive GET (Query String) data
  • Receive POST data
  • Send HTTP Response Status Codes
  • Send body response data
  • Send arbitrary HTTP response headers
  • View all system environmental variables

To get started quickly:

  1. Login to the Azure Portal
  2. Create a new function
  3. Link it to this Git repository
  4. Test the endpoint (https://myexamplefunc.azurewebsites.net/api/myfunction1)
  5. Look at the data logged in the Portal’s live feed

When you want to start editing and writing code yourself, feel free to fork my sample code. You can deploy via Git, or one of the other repositories offered in Azure:

Azure Continuous Deployment Options

Azure Continuous Deployment Options

For now all this is still a bit buggy (hence the “preview” label), but it does seem to work pretty well. Better support for Python is on the radar, so watch this space!

Get the Broadcast Technology Newsletter

Sign up for the email newsletter about media and technology. Sent irregularly. No spam.

I'm Anthony Eden, and I'm a broadcast technician / software developer / technology solutions engineer. I've been working in broadcast media since 2008 (getting my start in Community Radio while still at school), and developing software and websites for just as long. Right now, I work in the broadcast industry and provide some freelance services through Media Realm.

Follow Anthony on Twitter: @anthony_eden