I was investigating Azure Functions not so long ago when I came across the Azure Function challenge – a set of tasks posted by Microsoft for people to try out and learn about Azure Functions. Azure Functions is a relatively new (at time of writing) service offered by Microsoft, and is Microsoft’s version of AWS Lambda functions. It allows you to write a snippet of code which is triggered by certain events, and you’re charged by the number of times your code is executed and the memory consumption * time (measured in GB-seconds) of your executions. Here’s how I got started.
Editing tools
The first method of actually getting the code into Azure is directly through portal.azure.com. The second method is GitHub combined with Visual Studio Tools for Azure Functions, but it’s still in preview, has a particular set of prerequisites to install, and has a few known issues. However, the biggest advantages is that you get IntelliSense and you can run the code locally in an Azure simulator.
Triggers
Triggers are what cause your Azure Function to run, and you can select which trigger either through the Azure Portal, or by editing the file function.json in the Azure Function’s project directory. A few examples are triggers are BlobTrigger, HttpTrigger, QueueTrigger, and TimerTrigger. The file function.json
is where you configure triggers and data bindings.
Input and output binding
Once you get the trigger set up, you most likely will want to get at the input parameters, and also read or write to Azure Storage. For HTTP triggers, the HTTP request is bound by default to a request parameter called req, and the HTTP response is the return value. The example code provided by Microsoft does a good job of illustrating how to use both of them.
Accessing Azure Storage
Sometimes you want to access Azure Storage to… well, to store something from the request. I found the documentation here kind of lacking (Azure Functions hit v1.0 in November 2016) and figured this out through a lot of trial and error, so I hope someone finds this useful.
To write out to an Azure Table, first you need an actual Azure Storage Table… Assuming you have one set up, you need the account name, account key, the storage account’s connection string, and the target table name. Give the table parameter a name like tableBinding
, which you will use in code. This is what my configuration looks like in the Azure portal:
This is what the corresponding
function.json
looks like:
{
"bindings": [
{
"type": "httpTrigger",
"direction": "in",
"webHookType": "genericJson",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "table",
"name": "tableBinding",
"tableName": "AzureChallengeTable",
"connection": "azurefunctionsc99a8a83_STORAGE",
"direction": "out"
}
],
"disabled": false
}
Note the “connection” property, which is set to an environment variable which can be defined in your appsettings.json
file locally, or in the Azure Functions portal under Function app settings > Configure app settings > App settings section, and contains the connection string to the storage account. This is what allows you to access the Azure Storage account if you’re running locally.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AzureWebJobsDashboard": "",
"azurefunctionsc99a8a83_STORAGE": "ConnectionStringHere"
}
We configured the table binding to be called tableBinding, so our function signature now looks like this:
public static HttpResponseMessage Run(HttpRequestMessage req, CloudTable tableBinding, TraceWriter log)
You will also need to add #r Microsoft.WindowsAzure.Storage
to the top of the run.csx file and add using Microsoft.WindowsAzure.Storage.Table
(and import the Nuget package if you’re coding from VS). Now, we can insert objects that are a subclass of TableEntity (make sure you define how PartitionKey and RowKey are calculated) with a line like this:
tableBinding.Execute(TableOperation.InsertOrReplace(myEntity));
To read:
var tableResult = tableBinding.Execute(TableOperation.Retrieve<MyEntity>(partitionKey, rowKey));
var myEntity = tableResult.Result as MyEntity;
Deploying
If you wrote your code in VS, you can upload the project to GitHub, then use the Azure Functions portal to deploy the code to GitHub. One very important thing I noticed here is that the *.json and run.csx files must be at the top level of your repo; if you have multiple functions residing in multiple directories in the repo, Azure won’t find the code. So this basically means you need one repo per Azure Function.
One other quirk I noticed was that sometimes I got an HTTP 4xx response when testing, which was caused by an Azure bug with function keys. The workaround for this is to call the Azure Function with the key for the function, not the admin key (which is shared by all your Azure Functions).
In conclusion
Azure Functions (and AWS Lambda) is promising because it is simple, covers some very useful and common scenarios, and is easy to scale, but I found the documentation kind of spotty and hope it will improve in the coming months.
I’ve been following your blog for some time now, and I’m consistently blown away by the quality of your content. Your ability to tackle complex topics with ease is truly admirable.
RfpJTfLhh6X
gGwB2KzzO0E
3ouBt8RIPVc
Awesome https://lc.cx/xjXBQT
Good https://urlr.me/zH3wE5
Good https://is.gd/N1ikS2
Awesome https://is.gd/N1ikS2
Good https://is.gd/N1ikS2
Very good https://is.gd/N1ikS2
Good https://is.gd/N1ikS2
Awesome https://is.gd/N1ikS2
Top https://shorturl.fm/YvSxU
Top https://shorturl.fm/YvSxU
Cool partnership https://shorturl.fm/XIZGD
https://shorturl.fm/YvSxU
https://shorturl.fm/a0B2m
https://shorturl.fm/m8ueY
https://shorturl.fm/N6nl1
https://shorturl.fm/XIZGD
https://shorturl.fm/XIZGD
https://shorturl.fm/XIZGD
https://shorturl.fm/A5ni8
https://shorturl.fm/m8ueY
https://shorturl.fm/TbTre
https://shorturl.fm/bODKa
https://shorturl.fm/68Y8V
https://shorturl.fm/68Y8V
https://shorturl.fm/YvSxU
https://shorturl.fm/68Y8V
https://shorturl.fm/FIJkD
https://shorturl.fm/LdPUr
https://shorturl.fm/hevfE
https://shorturl.fm/JtG9d
https://shorturl.fm/fSv4z
https://shorturl.fm/TDuGJ
https://shorturl.fm/retLL
https://shorturl.fm/0oNbA
Unlock exclusive rewards with every referral—enroll now! https://shorturl.fm/YHctZ
Boost your income effortlessly—join our affiliate network now! https://shorturl.fm/mhWAV
Refer friends and colleagues—get paid for every signup! https://shorturl.fm/lAa8O
Start sharing, start earning—become our affiliate today! https://shorturl.fm/NY8av
Apply now and receive dedicated support for affiliates! https://shorturl.fm/BhbNM
Grow your income stream—apply to our affiliate program today! https://shorturl.fm/JYM5A
Monetize your traffic with our affiliate program—sign up now! https://shorturl.fm/1Zv3M
Apply now and receive dedicated support for affiliates! https://shorturl.fm/CNapV
Monetize your audience with our high-converting offers—apply today! https://shorturl.fm/NWl4c
Be rewarded for every click—join our affiliate program today! https://shorturl.fm/25om4
Promote our products and earn real money—apply today! https://shorturl.fm/i7e8w
Get paid for every referral—sign up for our affiliate program now! https://shorturl.fm/khHSX
Drive sales, collect commissions—join our affiliate team! https://shorturl.fm/pnMG8
Monetize your traffic instantly—enroll in our affiliate network! https://shorturl.fm/tZ5CN
Start sharing, start earning—become our affiliate today! https://shorturl.fm/ZmoqX
Your network, your earnings—apply to our affiliate program now! https://shorturl.fm/3ybPt
Drive sales, collect commissions—join our affiliate team! https://shorturl.fm/2g47e
Your influence, your income—join our affiliate network today! https://shorturl.fm/CIU9A
Grow your income stream—apply to our affiliate program today! https://shorturl.fm/Ep3Pd
Become our partner and turn referrals into revenue—join now! https://shorturl.fm/eUfak
Sign up for our affiliate program and watch your earnings grow! https://shorturl.fm/8enPc
Drive sales, earn big—enroll in our affiliate program! https://shorturl.fm/vwm2r
Your network, your earnings—apply to our affiliate program now! https://shorturl.fm/eL84r
Drive sales and watch your affiliate earnings soar! https://shorturl.fm/vrEyQ
Tap into unlimited earnings—sign up for our affiliate program! https://shorturl.fm/QJvzR
Share our offers and watch your wallet grow—become an affiliate! https://shorturl.fm/g5h3w
Maximize your earnings with top-tier offers—apply now! https://shorturl.fm/Egfi3
Maximize your income with our high-converting offers—join as an affiliate! https://shorturl.fm/zRCTi
Share our link, earn real money—signup for our affiliate program! https://shorturl.fm/ntXh2
Grow your income stream—apply to our affiliate program today! https://shorturl.fm/gBwdi
Sign up now and access top-converting affiliate offers! https://shorturl.fm/OIcfA
Earn recurring commissions with each referral—enroll today! https://shorturl.fm/ZxuMd
Sign up for our affiliate program and watch your earnings grow! https://shorturl.fm/GieXa
Share our offers and watch your wallet grow—become an affiliate! https://shorturl.fm/2uZXP
Join our affiliate program and start earning today—sign up now! https://shorturl.fm/8jAhI
Partner with us and enjoy high payouts—apply now! https://shorturl.fm/xSwgn
Drive sales, earn big—enroll in our affiliate program! https://shorturl.fm/WxCYu
Refer friends, collect commissions—sign up now! https://shorturl.fm/UnIkk
Apply now and receive dedicated support for affiliates! https://shorturl.fm/XmV5u
Partner with us and enjoy high payouts—apply now! https://shorturl.fm/N9RaW
Refer friends, earn cash—sign up now! https://shorturl.fm/k7Pvz
Unlock top-tier commissions—become our affiliate partner now! https://shorturl.fm/GPoVg
Join our affiliate program today and earn generous commissions! https://shorturl.fm/FDPpv
Join forces with us and profit from every click! https://shorturl.fm/CV23Y
Invite your network, boost your income—sign up for our affiliate program now! https://shorturl.fm/QPqjv
Grow your income stream—apply to our affiliate program today! https://shorturl.fm/roWq8
Drive sales, earn big—enroll in our affiliate program! https://shorturl.fm/xYLqR
https://shorturl.fm/q0mAE
https://shorturl.fm/X7D5t
https://shorturl.fm/x2AdT
https://shorturl.fm/mUJf5
https://shorturl.fm/Gw78a
https://shorturl.fm/j4eJn
https://shorturl.fm/6keSM
https://shorturl.fm/jCfgU
https://shorturl.fm/7VaVR
https://shorturl.fm/bMtrK
https://shorturl.fm/8fRrV
https://shorturl.fm/rrRnh
https://shorturl.fm/yjMix
https://shorturl.fm/RmpwU
https://shorturl.fm/DtuEA
https://shorturl.fm/AAzWR
https://shorturl.fm/84uQB
https://shorturl.fm/9ZfGx
https://shorturl.fm/Z9MRx
https://shorturl.fm/ZLXtF
https://shorturl.fm/vB6VN
https://shorturl.fm/hbfl1
https://shorturl.fm/xEZCz
https://shorturl.fm/2jMHO
https://shorturl.fm/TzeEB
https://shorturl.fm/Awdqs
https://shorturl.fm/AWB6U
https://shorturl.fm/oFs3Q
https://shorturl.fm/ce51C
https://shorturl.fm/ZVjz4
https://shorturl.fm/lySo9
https://shorturl.fm/Oi67f
https://shorturl.fm/UXJw4
https://shorturl.fm/3pEbM
https://shorturl.fm/LWJPj
https://shorturl.fm/HfQhH
https://shorturl.fm/8OzeE
https://shorturl.fm/Nhx2f
https://shorturl.fm/4Asx4
https://shorturl.fm/0gnJI
https://shorturl.fm/V9q7A
https://shorturl.fm/hjUpK
https://shorturl.fm/a0GEU
https://shorturl.fm/2K1Ed
https://shorturl.fm/qKodX
https://shorturl.fm/Jljo2
https://shorturl.fm/OPFsr
https://shorturl.fm/MQZOv
https://shorturl.fm/xwRLA
https://shorturl.fm/HfmZn
https://shorturl.fm/GUOXO
https://shorturl.fm/vtvKk
https://shorturl.fm/Mlvuf
https://shorturl.fm/QUF6A
https://shorturl.fm/6rgpc
https://shorturl.fm/vedNF
https://shorturl.fm/1svyX
https://shorturl.fm/J7H9G
https://shorturl.fm/SPbbG
https://shorturl.fm/8IU52
https://shorturl.fm/DRUl1
https://shorturl.fm/QEnhj
https://shorturl.fm/d7edH
https://shorturl.fm/Lb06j
https://shorturl.fm/GCEgc
https://shorturl.fm/Vbt8T
https://shorturl.fm/NHivt
https://shorturl.fm/4b7Zp
https://shorturl.fm/Xf4Yp
https://shorturl.fm/EppBQ