<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Masi Malmi on Medium]]></title>
        <description><![CDATA[Stories by Masi Malmi on Medium]]></description>
        <link>https://medium.com/@masimalmi?source=rss-a237c09e9845------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*6dwb4BGKy9fCVWE--hSvXg.jpeg</url>
            <title>Stories by Masi Malmi on Medium</title>
            <link>https://medium.com/@masimalmi?source=rss-a237c09e9845------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 15:53:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@masimalmi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building an event-driven .NET Core app with Dapr]]></title>
            <link>https://medium.com/polarsquad/building-an-event-driven-net-core-app-with-dapr-58cc83ab120b?source=rss-a237c09e9845------2</link>
            <guid isPermaLink="false">https://medium.com/p/58cc83ab120b</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[dapr]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[azure-event-grid]]></category>
            <dc:creator><![CDATA[Masi Malmi]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 09:54:00 GMT</pubDate>
            <atom:updated>2020-06-16T11:30:09.883Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building an event-driven .NET Core app with Dapr</h3><p>I had been waiting for the right moment to get back to coding and try out some of the new things I’ve been excited about lately. Although we get to play with the latest techs in our projects, the actual work is more geared towards the infrastructure and culture side of things. I think the last time I did coding in a client project was to implement some custom logic in Azure API Management policy using C# and that wasn’t much of a developer experience :)</p><blockquote>When you want to learn new tech, the best way is to just start building something.</blockquote><p>Initially, I wanted to try out some of the latest features of .NET Core 3.1 by building a simple application that could be run as a background process. Possibly containerizing it and running from Kubernetes. Triggered by Cloud Events from Azure Event Grid. And somehow utilize <a href="https://dapr.io/">Dapr</a> — “An event-driven, portable runtime for building microservices on cloud and edge.” — to put the bits and pieces together. It sounds like a nice microservice exercise for me!</p><h3>The app</h3><p>I wanted my app to do some meaningful (and cool!) work and maybe tackle a common use case I encounter in Azure projects. One such use case is events triggered by Azure Storage Account when new blobs are created. For meaningful work, I had been looking into <a href="https://docs.microsoft.com/en-us/azure/media-services/video-indexer/video-indexer-overview">Video Indexer</a> from Azure Cognitive Services. It would be interesting to find out what kind of metadata it’s able to extract from videos and store a subset of this to CosmosDb for later use.</p><blockquote>In short: once a new video file is uploaded to Blob storage the app receives an event, tells Video Indexer (VI) to index the file and once VI is finished processing it, the app writes the extracted metadata to CosmosDb.</blockquote><p>Since the app was going to receive events through a custom webhook it needed a REST endpoint and therefore I ended up implementing it as a <a href="https://docs.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-3.1">.NET Core Web API</a> application. The background process was accomplished using <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.1#queued-background-tasks">queued background tasks with hosted services</a>. This made it possible to keep the application itself asynchronous even though there was a long-running background task being executed as a singleton.</p><p>The free trial for Video Indexer provides 2400 minutes of free indexing <a href="https://docs.microsoft.com/en-us/azure/media-services/video-indexer/video-indexer-use-apis">when using the API</a> which was more than enough for my purposes. There are also code samples available in <a href="https://docs.microsoft.com/en-us/azure/media-services/video-indexer/">MS docs for Video Indexer</a> to get started.</p><p>High-level application architecture looked like this now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GDYerdAEReKxvEnxH9MEmQ.png" /></figure><p>Microsoft has a sample application for ASP.NET Core called <a href="https://github.com/Azure-Samples/azure-event-grid-viewer">Azure Event Grid Viewer</a> which showcases how to interact with Event Grid and <a href="https://github.com/cloudevents/spec/blob/v1.0/json-format.md">Cloud Events</a>. I borrowed some of the logic and models from there.</p><p>You can find the full source code for my app from <a href="https://github.com/Masahigo/video-indexer">Github</a>.</p><h3>Enter Dapr</h3><p>I had heard about this technology called <em>Distributed application runtime (Dapr)</em> already in autumn 2019 when <a href="https://cloudblogs.microsoft.com/opensource/2019/10/16/announcing-dapr-open-source-project-build-microservice-applications/">Microsoft announced the open-source project</a> they were working on. Since then it has gained a lot of momentum and is currently in version 0.7.1.</p><h4>What’s it about?</h4><p>Dapr is a runtime for building microservice applications. It provides a growing collection of ready-made building blocks and removes the need for common boilerplate code for integrating to some of the most popular cloud services and technologies needed in distributed applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oB_h5md-s8_QaMuffvjYHQ.png" /><figcaption>Overview of Dapr (source: <a href="https://github.com/dapr/docs/tree/master/overview">dapr.io</a>)</figcaption></figure><blockquote>It’s a platform-agnostic way of building modern cloud-native applications.</blockquote><h4>Getting started</h4><p>The <a href="https://github.com/dapr/docs">official documentation</a> seems to be on a very good level already but surprisingly it lacks concrete examples for .NET. Most of the samples are for either Go, Node.JS, or Python and therefore it took a little bit of extra effort to get started.</p><p>I found one <a href="https://github.com/ToonVanhoutte/dapr-samples/blob/master/README.md">series of blog posts</a> particularly useful from Toon Vanhoutte which covers the basics. Be aware though that Dapr is constantly developed further and some of the older examples you find (outside of Dapr’s documentation) might not work with the latest version.</p><p>Currently, Dapr supports two modes</p><ul><li><strong>Standalone (self-hosted)</strong>: this is the mode you use when developing Dapr enabled applications in your local development environment</li><li><strong>Kubernetes</strong>: this is the mode you use for hosting your Dapr enabled applications</li></ul><p>You also need Docker, regardless of the mode. Dapr runs on Linux containers.</p><h4>Developing and debugging using VSCode</h4><p>It was quite straightforward to get started with Dapr using VSCode. I found this <a href="https://blog.ehn.nu/2020/03/debugging-dapr-applications-with-visual-studio-code/">excellent blog post</a> on getting the VSCode configs just right. Being able to debug your code properly is an absolute must and time saver. It also helps a lot when you can use the native debugging functionality from VSCode and output the application and Dapr logs to separate windows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_65q3ROK4ka1T1At" /><figcaption>Debugging application with Dapr from VSCode</figcaption></figure><p>There are two VSCode extensions I found particularly useful</p><ul><li><a href="https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-dapr">Dapr for Visual Studio Code (Preview)</a>: eg. <em>Dapr: Scaffold Dapr Tasks </em>was needed for setting the configs right</li><li><a href="https://marketplace.visualstudio.com/items?itemName=Dunn.redis">Redis Manager (Preview)</a>: Dapr uses Redis as a default state manager and it helps to see the data you save in the state</li></ul><h4>Building blocks</h4><p>Dapr provides several <a href="https://github.com/dapr/docs/tree/master/concepts#building-blocks">building blocks</a> to choose from. Since I was building just a single microservice it didn’t need to communicate with other than external resources.</p><p>I chose the following Dapr building blocks for my application</p><ul><li><strong>State management</strong>: I store the data being consumed (cloud event) and processed (video index) temporarily in Redis while the background task is doing work. Once the work finishes the app removes them from the state.</li><li><strong>Resource bindings and triggers</strong>: There’s an Event Grid input binding for Cloud Events and CosmosDb output binding for writing the metadata.</li><li><strong>Secrets</strong>: Used for integrating with Azure Key Vault. Utilized only in Kubernetes deployment because I encountered some encoding issues with the certificate file and the Windows file system when Dapr was initializing the azurekeyvault component in local development environment</li></ul><p>This is what my application architecture looked like with Dapr in Standalone mode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xYjDZkGSpIo1tH0MK2htmw.png" /><figcaption>Local development environment with Dapr (Standalone)</figcaption></figure><h4>Testing locally using Dapr components</h4><p>I was using three Dapr components when developing the application</p><ul><li><a href="https://github.com/dapr/docs/blob/master/reference/specs/bindings/eventgrid.md">Azure Event Grid Binding</a></li><li><a href="https://github.com/dapr/docs/blob/master/reference/specs/bindings/cosmosdb.md">Azure CosmosDB Binding</a></li><li><a href="https://github.com/dapr/docs/blob/master/reference/specs/bindings/redis.md">Redis Binding</a></li></ul><p>CosmosDb and Redis Dapr components were straightforward to configure. Dapr creates the Redis state store component file automatically when you run your application with Dapr for the first time in Standalone mode.</p><p>But the Event Grid binding was a relatively new Dapr component and required some extra steps to get it fully working. With the help of the component’s author, I managed to figure out how to work with it and the official documentation <a href="https://github.com/dapr/docs/blob/master/reference/specs/bindings/eventgrid.md#additional-information">now covers all the steps needed</a>. Dapr’s community is very helpful in these things and there’s also <a href="https://gitter.im/Dapr/community?at=5daf3789f26ea4729dd6fc36">a channel in Gitter</a> where you can ask your questions if and when you get stuck.</p><p>There’s one thing I realized later on when testing my application with Azure Event Grid. It makes sense to separate the Event Subscriptions per environment. In practice this means having a unique name in the Dapr component for each environment (note the suffix <strong>-local</strong>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fd41d9f31eddb26822ea49b4a0335e2/href">https://medium.com/media/7fd41d9f31eddb26822ea49b4a0335e2/href</a></iframe><p>Since this is mapped directly to your application’s endpoint, you need to make sure it knows to expect POST requests to specific URL for <a href="https://github.com/dapr/docs/tree/master/howto/trigger-app-with-input-binding#2-listen-for-incoming-events">listening incoming events</a>; In this case, starting with eventgrid-input- and then handling the Cloud Events accordingly.</p><p>I decided to map this environment-specific endpoint (route) explicitly to the controller handling incoming events in <em>Startup.cs</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee8b6087d0ea403a5f0d86065c65bdf0/href">https://medium.com/media/ee8b6087d0ea403a5f0d86065c65bdf0/href</a></iframe><p>You can check from my app’s controller how the <a href="https://github.com/Masahigo/video-indexer/blob/master/Controllers/VideoIndexerController.cs#L47">receiving endpoint</a> was implemented.</p><p>The result in the Azure portal when having multiple environments should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EWVO7mCIP5qPeqim" /><figcaption>Azure Storage Account Event Subscriptions created by Dapr binding</figcaption></figure><p>I used Ngrok to create a public HTTPS URL pointing to my local dev environment.</p><h3>Deploying to Kubernetes</h3><p><em>If you jumped right into this section and are wondering why I’m deploying this simple app to Kubernetes my answer to you is simple: this is currently the only recommended (read: defacto) way to host Dapr for the time being. Sure you could set up your server or VM, install Docker runtime there, and get things going but there must be a reason why I haven’t found anyone trying that…</em></p><p>Things were looking mighty fine. Once I had the basic functionality finished I <a href="https://github.com/Masahigo/video-indexer/blob/master/Dockerfile">containerized my app</a>, verified that it works in Docker container, and pushed the container image to Docker Hub. I also added basic <a href="https://github.com/Masahigo/video-indexer/tree/master/HealthChecks">health checks</a> for checking app liveness and connectivity to Video Indexer API.</p><blockquote>The last step was to deploy this thing to Kubernetes and see it in action. How hard could that be, right?</blockquote><h4>Public webhooks</h4><p>There are two things to know about Azure Event Grid and custom webhooks</p><ul><li>It allows only HTTPS subscribers</li><li>It accepts only real SSL certificates, self-signed won’t do</li></ul><p>What this means in practice is that you need to expose a valid HTTPS endpoint from your k8s cluster so that Azure Event Grid can validate it and do the handshake. But since this communication happens through Dapr it gets even trickier.</p><p>Luckily Carlos Mendible had already <a href="https://carlos.mendible.com/2020/04/05/kubernetes-nginx-ingress-controller-with-dapr/">figured out a way</a> to expose traffic from public internet to Dapr sidecar in Kubernetes cluster using Nginx based ingress controller. Now it was just a matter of configuring the correct k8s networking in place.</p><h4>Daprizing your ingress controller</h4><p>A majority of the examples using Dapr you will find out there are exposing applications directly to the internet when deployed to Kubernetes. This is fine for demo purposes but any real-world application running in k8s is usually exposed through an ingress controller. If you’re interested in a proper sample/reference application I recommend checking out <a href="https://code.benco.io/dapr-store/">Dapr Store</a>.</p><p>When you deploy Dapr to Kubernetes cluster <a href="https://github.com/dapr/docs/blob/master/getting-started/environment-setup.md#installing-dapr-on-a-kubernetes-cluster">following the instructions from Dapr docs</a> you have everything you need for running the application with Dapr. But without a <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/">k8s ingress</a>, any endpoint exposed from Dapr is unreachable.</p><p>To enable Azure Event Grid to communicate with Dapr’s sidecar in k8s cluster this was needed to happen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E1MgyXdRzz8S9p2xWtcAVQ.png" /><figcaption>Routing incoming events from Event Grid to Dapr in Kubernetes cluster</figcaption></figure><p>After a lengthy discovery mission into getting the Nginx based ingress right I managed to get it finally working:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d3f935c683fedb1455e1679ae712bb9/href">https://medium.com/media/4d3f935c683fedb1455e1679ae712bb9/href</a></iframe><p>The biggest issues I had were related to keeping the Nginx ingress controller’s routing rules in sync with its Dapr sidecar. These were resolved by “resetting” the Ingress pod.</p><p>You can find all the files related to the app’s Kubernetes deployment <a href="https://github.com/Masahigo/video-indexer/tree/master/deploy">from here</a>.</p><h4>Putting the pieces together</h4><p>As part of deploying my application to k8s, I introduced Dapr’s <a href="https://github.com/dapr/docs/blob/master/howto/setup-secret-store/azure-keyvault.md">Secret Store for Azure Key Vault</a>. It’s a way to enable Dapr to read secrets directly from the Azure Key Vault and reference the values from its components. You can check the docs on <a href="https://github.com/dapr/docs/blob/master/howto/setup-secret-store/azure-keyvault.md#use-azure-key-vault-secret-store-in-kubernetes-mode">how to configure it to k8s</a>.</p><p>This is what the finalized architecture looked like with Dapr in Kubernetes mode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hq41xpoLVQLSp7H8R1-1xQ.png" /><figcaption>Video indexer application running with Dapr in a Kubernetes cluster</figcaption></figure><p>For injecting secrets from Azure Key Vault to the app’s environment variables I’m using <a href="https://akv2k8s.io/stable/azure-key-vault-env-injector/README/">Azure Key Vault Env-Injector</a>. It’s run as an init container in the application’s pod. Dapr provides an API for accessing the secret store but I liked the idea more of injecting the secrets directly to the pod.</p><p>Complete steps for the k8s deployment are <a href="https://github.com/Masahigo/video-indexer/blob/master/README.MD#steps-to-deploy-to-kubernetes">explained here</a>.</p><h3>Looking into the future</h3><p>Dapr seems like a very viable option for building microservice applications. It’s still not production-ready but I was surprised how well it worked already. It’s very lightweight and doesn’t get into your way. The developer experience was nice as well, once you had the basics covered.</p><p>I was testing it with just a single microservice, but its real power is tested when you need a consistent way for building distributed microservices that need to communicate with not just each other but different technologies and services from several cloud providers. Building a true multi-cloud software and/or IoT solution hosted from Kubernetes are perfect places to take this emerging technology into use.</p><p><a href="http://www.polarsquad.com/">www.polarsquad.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58cc83ab120b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/polarsquad/building-an-event-driven-net-core-app-with-dapr-58cc83ab120b">Building an event-driven .NET Core app with Dapr</a> was originally published in <a href="https://medium.com/polarsquad">Polar Squad</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Discovering CI/CD for APIs in Azure Api Management]]></title>
            <link>https://medium.com/polarsquad/discovering-ci-cd-for-apis-in-azure-api-management-d4be0667fa84?source=rss-a237c09e9845------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4be0667fa84</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[api-management]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Masi Malmi]]></dc:creator>
            <pubDate>Tue, 03 Mar 2020 10:46:55 GMT</pubDate>
            <atom:updated>2020-03-13T21:44:15.203Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JfPJP74zARgnbWTp" /><figcaption>Photo by <a href="https://unsplash.com/@danielcv_93?utm_source=medium&amp;utm_medium=referral">Daniel Cartin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I started my journey with <a href="https://docs.microsoft.com/en-us/azure/api-management/">Azure Api Management</a> (APIM) in spring 2019. My client had an API strategy in place and needed someone to take it forward i.e. plan the architecture and start implementing the infrastructure (as code, naturally) and publish the first APIs using it. The setup needed to be as secure as possible but at the same time serve the needs of different teams and stakeholders, enable hybrid networking scenarios and integrate into a 3rd party IAM (SaaS) product. <em>I really had no idea where I was putting myself into.</em></p><p>One of the most valuable lessons I learned during this exercise was figuring out how to apply a CI/CD process for APIs published through APIM. <em>It took several iterations and learning the hard way, so I figured to share the story.</em></p><h3>The basics</h3><p>APIM offers <a href="https://azure.microsoft.com/en-us/pricing/details/api-management/">several different pricing tiers</a> to choose from. But if you’re after true network isolation (=Virtual Network support) the only tiers supporting this are <em>Developer &amp; Premium</em>. This leads, in most cases, into a centralized model where all the teams are publishing their APIs through a shared production APIM environment. APIM in <em>Premium tier</em> costs over 2k€ / instance / month so minimum setup is 2 instances, although they reside in the same region by default. To have true HA for your APIM setup requires some extra planning and work.</p><p>APIM can be run in <em>three modes</em><br>- <strong>Public</strong>: open to internet and Azure controls the DNS<br>- <strong>External</strong>: open to internet and Azure controls the DNS + VNET integration<br>- <strong>Internal</strong>: no connection to internet, you manage the DNS + VNET integration</p><p>Azure Api Management is basically a managed high level API gateway, a facade for your APIs. It involves substantial costs in terms of extra work to manage and run it. You can survive with much cheaper running costs if VNET support is not a must and most companies go with the <em>Standard tier </em>in production, I’ve heard. It just means they use some means of authentication to protect the endpoints in APIM but they’re all open to public network.</p><blockquote>Then why would I want to publish my APIs through APIM and not just implement x number of custom API gateways to achieve the same? The main advantage it gives you is the ability to easily share the APIs through this facade to partners and 3rd parties as well as internal developers in a centralized and controlled manner.</blockquote><p>For instance, you can enforce policies and group APIs under “products” to which consumers can then subscribe to. This is usually relevant to larger Enterprises and service providers building digital platform capabilities and API economy.</p><h3>Networking considerations</h3><p>APIs published through APIM can be hosted virtually anywhere. In our case however, we were running it in <em>internal mode</em>. Therefore it was desirable to keep the traffic inside Azure backbone when forwarding it between APIM and APIs. For routing traffic from public network to APIM (internal) you need some service in front of it. In Azure’s managed offering this is usually Application Gateway (AppGw).</p><figure><img alt="Api Management running in internal mode under Hub Vnet with AppGw and Key Vault." src="https://cdn-images-1.medium.com/max/1024/1*XKszBweDgb3eglrK1jDPUw.png" /><figcaption>Example of an APIM production setup running in internal mode</figcaption></figure><p>When planning for the needed subnets and IP ranges you need to take into account at least the following</p><ol><li>How many <em>centralized</em> (not owned by projects and/or teams) APIM environments you intend to have</li><li>Max instance count in AppGw needed to support the highest user loads</li></ol><p><em>These two are the biggest factors in defining the CIDR needed for your centralized APIM environments. These also account for only one region.</em></p><p>Another challenge related to this topic is to what Azure network should you place these resources. I spent fair amount of time myself weighing different options and came into the conclusion that it’s easiest and most efficient to provision them directly under Hub’s own VNET.</p><p>In the <a href="https://docs.microsoft.com/en-us/azure/architecture/reference-architectures/hybrid-networking/hub-spoke">Hub and Spoke network topology</a>, resources under the Hub’s network are automatically connected to Spoke’s resources. I didn’t want to start replicating the VNET peerings to some other VNET just to complicate things, not to mention the added round trips and needed firewall openings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hl-5qrU_04qazmBVmW2z6w.png" /><figcaption>Hub and Spoke network topology with ExpressRoute</figcaption></figure><h3>Infrastructure As Code</h3><p>My philosophy when it comes to IaC is quite simple. Use the native tooling that the platform provides. In Azure this translates to <a href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/overview">ARM</a>. I did take a serious look into <a href="https://www.terraform.io/">Terraform</a> also when investigating the options, but decided to stick with ARM, mainly because I was under time pressure, had better experience on it, and all the available examples were using it.</p><blockquote>As usual, you also need some scripting language to make the last mile. I used both Azure CLI and PowerShell Core when convenient. With some of the newest services PS is the only thing that works from day one really.</blockquote><p>I had a rough start however, because I found to my disappointment that the ARM template you export from existing APIM environment cannot be used as is, even though you’d strip all the extra stuff away, it still doesn’t work. Luckily there are some vanilla examples in the <a href="https://github.com/Azure/azure-api-management-devops-resource-kit/tree/master/example">Azure Api Management DevOps Resource Kit</a> to get started.</p><p>After I’d automated the creation and update of APIM environments I started plugging in the first APIs. I used the <a href="https://github.com/Azure/azure-api-management-devops-resource-kit/blob/master/src/APIM_ARMTemplate/README.md#extractor">Extractor tool</a> for generating ARM templates from existing APIM (dev) environments where teams had published their APIs initially. The tool had some shortcomings which one had to manually fix afterwards but things were progressing, as long as I worked the ARM myself.. but it was soon becoming clear that teams would need a lot of support using this approach. Most of the devs didn’t have previous experience from ARM and they even struggled figuring out how to work with APIM. <em>It was time for some changes.</em></p><h3>You build it, you run it</h3><p>I had heard about this company called VIPPS in Norway who had a very similar situation. After watching <a href="https://vimeo.com/318813322">their presentation on this</a> it hit me. There’s no way this is going to work if I try to do the work for the teams/projects when they should be in fact owning the APIs life cycle and the APIM part that involves it. I’m only making myself a bottleneck and hindering others taking ownership of their APIs. <em>In practice this means the API’s schema and APIM policy needs to live in the same code repository where the API is developed. And teams will handle publishing (syncing) the API schema changes to APIM as part of their regular CI/CD process.</em></p><p>I started working towards this new goal and having discussions with tech leads from different projects. We came into a mutual understanding of how the <strong>CI/CD flow for deploying APIs to Azure Api Management </strong>should work</p><figure><img alt="CI/CD flow for deploying APIs to Azure Api Management" src="https://cdn-images-1.medium.com/max/1024/1*8b6-h_vAfQs40L-bi1NGrA.png" /></figure><ol><li>Developer <em>commits new code to repository through pull request</em> reviewed and approved by another developer. This triggers a new build in the CI pipeline through a web hook.</li><li>All the <em>stages in the CI/CD pipeline are run inside a container. The container image can vary between stages</em> and is fetched from a private image repository.</li><li>If/when the test stage is passed, it’s time to validate the API schema. Schema should be generated dynamically during the build stage and passed to later stages using build artifact. <em>If/when validation is passed the API schema is stored to version control.</em></li><li><em>Deploy stage takes care of deploying the latest code</em>, output from build stage, <em>to the actual environments where the API is hosted. </em>If blue-green deployment is used, the new code would be deployed to staging slots here.</li><li><em>Publish stage updates the latest API schema to APIM environments.</em> Before this happens though, we should check from code repository if the checksum for api schema has changed. <em>If the APIs schema has not changed since previous build(s) there’s no need to update the API in APIM environments.</em></li><li>After the API CI/CD pipeline has run through successfully it’s time for the developers to take charge and ensure everything is running as expected. In order to monitor the centralized APIM environments’ metrics they need read permissions (RBAC) to those but only the credentials used in CI/CD have enough privileges to update the APIs.</li></ol><h3>Final thoughts</h3><p>Working with Azure Api Management is team work. It involves coordination with all third parties as well as internal IT and development teams. Teaching and coaching the teams plays a crucial role. Ideally a DevOps team owns the centralized APIM environments and provides tooling and guidance for teams/projects in regards to implementing the publish stage to APIM as part of their existing CI/CD pipelines in a common way and establishing operating models to meet SLAs and end-to-end monitoring.</p><p><a href="http://www.polarsquad.com/">www.polarsquad.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4be0667fa84" width="1" height="1" alt=""><hr><p><a href="https://medium.com/polarsquad/discovering-ci-cd-for-apis-in-azure-api-management-d4be0667fa84">Discovering CI/CD for APIs in Azure Api Management</a> was originally published in <a href="https://medium.com/polarsquad">Polar Squad</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>