How to create infrastructure with Serverless Framework (Azure)

The serverless framework’s azure provider is great. The azure function serverless plugin allows for creation of Azure functions with ease. They also provide all the bindings you need to kick start your function with a new event from a service bus, a new drop in blob storage or even to process a new event on an EventHub topic.

But what if your function needs to store its processed data on another cloud resource? say a blob storage or service bus?

The good news is the azure functions plugin does provide a way for you to create those resources as well. Albeit it’s more of a hidden feature and something that isn’t well documented. I am doing to cover this scenario here with hopes that it will help someone out there.

Disclaimer: This article assumes that you have a good understanding what serverless framework is (and does) and you also have a basic understanding of development for azure and ARM templates.

The documentation for the plugin, specifies that you can provide a path to an ARM template. The field to provide in your severless.yml is armTemplate . Here is an example:

template.jsonis a file that contains the ARM definition. In my case here, it includes the definition for creating a service bus queue. The queue is a location where my function will store its results on.

Now if you run sls deploy you’ll see that serverless will create the Azure function resources as well as the service bus we specified in our ARM template:

It really is that simple and it’s a pity that this feature isn’t documented at all.

The fun, however, ends here. As of right now, I couldn’t find any ways to reference the resources that were created via my ARM templates in my serverless.ymlfile. This is wildly important since as I mentioned earlier, my Azure function will be storing data on this Service Bus queue and I need to know it’s connection string in my function’s application settings.

This is a missing feature and I have submitted a feature request to the plugin owners. I would love to be the one implementing it, only if weekends had 4 days in them.

For now, I went down the route of using a simple workaround. I created a simple bash script that grabs the connection str from service bus and updates the azure function application settings with it:

Then I bundled the script in a command for npm to deploy and configure.

Please keep in mind that such workaround only works with small deployments like mine. For a bigger and more complex scenario, always go down the route of Terraform scripts. They’re very versatile and easy to use. They can in fact, even do the same deployments that serverless does quite easily (as there are many sample scripts online for azure functions you can already use).

Ultimately, I still feel this would be an interesting feature to add to Serverless.

I hope you found this article useful. Good luck.

A tech enthusiast who presides in a jungle.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store