Change the Azure Functions system keys
I was recently asked how to change Azure Functions’ system keys, such as the ones automatically created by the Event Grid or Durable Functions extensions.
It’s possible to change these keys via the Azure portal. There is a button in the portal to generate a new key.
What if you want to change the keys programmatically? I couldn’t find official documentation which stated how to do so. After a bit of splunking through GitHub issues (here, here) and reading Mark Heath’s excellent blog post on Azure Function keys, I think I found an approach that, so far, seems to work.
If there is official doc and I missed it, please let me know in the comments below.
Before changing the keys, I’d like to retrieve the current keys. If I can retrieve the keys through an API, I feel that is a good indication that I should be able to update the keys.
Get the keys
To get the keys, I’m going to use the Azure CLI’s az rest
command.
|
|
I should get a response like the following:
|
|
Now that I can retrieve the keys, I’d like to change the Event Grid extension key, eventgrid_extension
.
Update the keys
I’ll use the Azure CLI’s az rest
command again to update the keys.
|
|
The content of the body.json file is as follows:
|
|
The output of running that az rest
command to change the key is as follows:
|
|
I had Application Insights hooked up to my function app so I could monitor what happens when I attempt to update the key. By watching Live Metrics, I can see the runtime detects the change.
Conclusion
It is possible to view and change the Azure Functions system keys via a REST API. Oh, and the az rest
command in the Azure CLI is fantastic!
Resources
- Mark Heath’s Managing Azure Functions Keys (using the new ARM APIs!) blog post. It’s excellent!!
- Key management API. It’s old, but still helpful.