Although you can inject your ILogger<T> into the constructor of your function, sometimes you may want to use the FunctionContext from your trigger method. Mocking this for testing can be a bit tricky. Consider the following function: public class MyFunction { [Function("MyFunction")] public async Task Run([ActivityTrigger] FunctionContext executionContext) { var logger =...
Using nginx to send webhooks to multiple upstreams
Forwarding webhook requests from a single endpoint, to multiple ‘upstream’ endpoints could be useful in many scenarios. A lot of applications that dispatch webhooks only allow one url, however, which can be a bit of a limitation. This pattern also simplifies maintenance. For instance, you can whitelist the relay IP while keeping your upstream endpoints on a separate network. Additionally, you...
Is user-agent a privacy concern?
Recently, I had a discussion with an e-commerce client about the implications of logging user-agents for their customers. Are there any privacy concerns involved? Can this data be used for anything other than identifying the browsers customers use to visit the site? And what about customers browsing in incognito mode – does the user-agent reveal that? To find out, I decided to conduct a quick...
Cosmos DB Change Feed Processed by Azure Functions – Application Insights Telemetry
While working with a Cosmos DB Change Feed processor running as an Azure Function, I noticed that ‘requests’ are logged as Application Insights telemetry, but show up with no URL, and a response Code of 0. I was able to reproduce this using a lean example, generated from the func new generators. (Code available here: ) I’m trying to figure out why this is, so this is a kind of...
‘No resources found’ error when publishing to Azure App Service using Visual Studio 2019
Yesterday, I tried to publish an app to Azure App Service from Visual Studio 2019 (right-click -> publish) (I know, I know… but I just wanted to try this feature out!) I had already set up my Linux App Service Plan (size B1) On clicking publish, and selecting “use existing” I was seeing a rather unhelpful “no resources found” message Of course I’d tried the usual ‘log...
Amazon is blocking my VPN (which is hosted on AWS!)
I run a very simple OpenVPN server in an Amazon Lightsail VM. This is to provide me with a ’static’ IP address, I can whitelist for access to some services. However, recently, I’ve noticed Amazon (.co.uk) has been blocking me from using the shopping site when connected to my VPN. I will get the following 503 error: It seems Amazon themselves don’t ‘trust’ the traffic coming...
NSwag build error – Project file does not exist / Unable to retrieve project metadata
While working on a project that used NSwag, when the solution was built, Visual Studio (and dotnet build from the command line) reported the following error: View the code on Gist. Pretty frustrating, as it wasn’t clear what the error meant. This project used NSwag.MSBuild to generate the client on build. As per their documentation, we had an after build target: View the code on Gist. The problem...
Opening first few lines of a huge file with VS Code
I’m currently doing some work looking at the GeoNames dataset. `allCountries.txt` is around 1.5gb, which is pretty large, and certainly too large to open up in vscode for a quick look. However, I found I could use `head` command, which reads the first n lines of a file, and pipe the output to `code -` (which is the command for opening vs code and reading the output from another program) For...
Using Google Sheets and Azure Functions as a headless CMS
One of my clients came to me with a relatively simple requirement; they needed to take online payments for their fitness event photography business. The model is quite simple: There are several different competition dates per year. Competitors can purchase professional photos of themselves at a competition. Each competitor will have a ‘badge number’ to identify them. If purchased before the...
Using Mediatr with Azure Functions
I’ve used Mediatr for some time, to reduce controller action bloat, and have spoken about it a few times, on how I use it to avoid the classic ‘xService’ pattern: Controller Action -> ‘Service’ -> Repo Lately, I’ve been doing a lot of work with Azure Functions, and would like to be able to use Mediatr, as I can in ASP.net Core. Up until recently, this has...
Reliably Processing Azure Service Bus Topics with Azure Functions
At ASOS, we’re currently migrating some of our message and event processing applications from Worker Roles (within classic Azure Cloud Services) to Azure Functions. A significant benefit of using Azure Functions to process our messages is the billing model. As an example, with our current approach, we use a Worker Role to listen to subscriptions to Azure Service Bus topics. These Worker Roles are...
Disable gzip responses in Azure Functions
By default, responses from Http Triggered Azure Functions are gzipped: Not all clients are able to handle this (although they should be) Turning it off isn’t particularly trivial. A change needs to be made to applicationhost.config – which is located in LocalSiteRoot/Config However, this file is readonly, so the change needs to be made via a xdt transform. In the Azure portal...
Better assertions when verifying Moq’d methods have been called
Moq, according to its GitHub page, is “The most popular and friendly mocking framework for .NET”. Mocking frameworks allow you to create a ‘fake’ version of a dependency (typically an interface, or abstract class). With this fake, you can then instruct the methods return values, or invoke behaviour. Alternatively you can assert the methods were called, with a certain set...
Reversing hashes of PwnedPasswords api using number of breaches
I was recently working on a requirement to log the number of breached sites a password appeared on when customers were registering (if that password had been breached at all) Importantly, we are not logging the breached password itself (nor the hash of the password) – just the number of breaches that particular password appeared in (as per the Pwned Passwords data set) So, to log this, I’m...
Hide Sensitive Data with Application Insights JavaScript SDK using a Telemetry Initializer
Application Insights is incredibly powerful, especially when using the JavaScript Client SDK.
The problem is, sometimes we can be logging a little too much.
We can use a Telemetry Initalizer to hide sensitive data in dependencies / requests logged with Application Insights.
Quickly add GSuite (Google Apps) MX Records to CloudFlare DNS
As some people know, I run a web development agency called Cohoda LTD. As part of our service, like most development agencies, we offer web hosting. To keep things as lean as possible, we deliberately don’t try to host email servers ourselves, instead we set up clients with email on Google GSuite (or Office 365 if the client prefers) I always (where possible) use CloudFlare for DNS, and found...
Search git branch names using command line
Looking for a particular branch, and `git branch -a` returns a LOT of branches? If on Windows, you could use the Search feature in cmder (you’re using cmder, right?) Or on mac, cmd+f and then search the outputted text… OR you could use one of these two approaches: 1) git branch takes a `–list` argument , which in turn takes a search arg. Example: git branch -a --list *something*...
Adding additional colour themes to Jetbrains Rider
color-themes.com according to it’s description, offers “Color themes for IntelliJ IDEA, Webstorm, PyCharm, RubyMine, PhpStorm and AppCode” However, it turns out that these themes also work with Rider. After downloading it (it’s a .jar file) go to File > Import Settings Choose the downloaded .jar file, and it will import the colour theme. Once Rider restarts, the theme will be available...
An Introduction to the LEDS Stack
Full blog post is coming soon.
For now, please see GitHub repository for demo project:
Talk slides at:
Azure function not receiving json messages using Topic Service Bus Trigger
While developing an Azure Function application, using this tutorial, I encountered a problem. Ultimately, using `func new` generated my function (the run.csx file) which looked like this: public static void Run(string mySbMsg, TraceWriter log) { log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}"); } Side note: the `mySbMsg` is important – it’s defined in the...
Asserting multiple properties of argument with FakeItEasy
More often than not, I want to assert that my dependency has been called with a parameter that matches more than one condition. Let’s say we have a method that calls ICustomerService.Add method. We want to assert the Add method was called with a Customer that matches a few conditions. The way we’d typically achieve this is by doing something like this: var fake = A.Fake<ICustomerService>();...
Physical 419 Letter Received
Last night I opened an innocuous looking letter delivered to my home address. It had a ‘commercial’ postage stamp on it (not one that you’d pick up in the post office) and it wasn’t addressed to anybody on the envelope. The content of the letter was what I’d expect to get via email – a 419 scam! It was, however, addressed to the previous occupier of the house...
Microsoft SQL Server on a Ubuntu Linux VM
As part of a blog post on the LEDS stack (Linux Nginx Dotnet, SQL Server) I’m putting together, I wanted to see how easy it is to install SQL Server on a Ubuntu VM, running on Digital Ocean. Turns out, very easy. I went with a Ubuntu 16.04.2 x64 box, with 4GB of RAM The docs state that you need at least 3.25GB of memory to run SQL Server on Linux. Once my droplet had created, I SSH’d into it...
Using different themes across Visual Studio versions
I’m currently working on a couple of solutions – one that is Visual Studio 2017 specific, one 2015. Primarily because the 2017 specific one is full of .net standard projects, and the support is better (or at least, built in) I wanted to have 2015 use a different theme – I’m only doing small bits in it, but have them both open at the same time, so figured having one light...
Out Of Memory exception when deserializing with JSON.net – Use Streams instead
Calling an api and deserializing the returned json into a type is something I have to do quite often. I used to use the following: //assume client is an instance of HttpClient - this part isn't important var response = await client.PostAsync(url, content); //read the response as a string var responseString = await response.Content.ReadAsStringAsync(); //use json.net to deserialize this into a...