azure api management,

Azure API Management with PowerShell

Sven Malvik Sven Malvik Connect Mar 21, 2020 · 2 mins read
Azure API Management with PowerShell

We use a lot of PowerShell to provision the Azure infrastructure that powers Vipps AS today. PowerShell is actually a great choice for using working with APIM since it great supported. The PowerShell for Azure is actually using the REST API, so you can expect to get the same support. In case you would like to see the REST API in action for provisioning API Management, you can follow the link. I will use PowerShell to provision an instance of API Management today.

Let’s start by connecting to our Azure account by executing this PowerShell code:

Connect-AzAccount -SubscriptionId "<SUBSCRIPTION_ID>" -Tenant "<TENANT_ID>"

You will be redirected to Microsoft within your browser to login. When everything is correct, you can proceed in your PowerShell editor.

Whenever we provision a resource, we need to add it to a resource group. In case you didn’t create one previously, you run this code:

New-AzResourceGroup -Name "apim-rg" -Location "West Europe"

It’s always a good idea to tag your resources. We’ll cover this in a later post.

Deploying API Management

Now it’s time to deploy an instance by executing this PowerShell code:

New-AzApiManagement -ResourceGroupName "apim-rg" -Name "apim-service" -Location "West Europe" -Organization "<ORGANIZATION>" -AdminEmail "sven@malvik.de"

The deployment takes about 2 minutes. In case we’d deployed with SKU Developer, we’d need to wait up to an hour. You can verify this by going into your portal and navigate to your new instance.

Importing an API

It’s not part of this post, but I really want to show it because it’s very simple as well. What you need is a Swagger-file. There are many other options of creating an API, but that is part of a later post as well. I will use the public available Conference API and put the link to it in a variable.

$SwaggerfileUrl = "https://conferenceapi.azurewebsites.net?format=json"

We need to create a context. We are basically telling what instance of APIM we want to use. Specify the resource group and the name of your instance.

$apimContext = New-AzApiManagementContext -ResourceGroupName "apim-rg" -ServiceName "apim-service"

Finally, we can import the API by defining the url of our swagger file, a path that a request will use to reach the API, and an ApiId that you can choose yourself.

Import-AzApiManagementApi -Context $apimContext -SpecificationFormat "Swagger" -SpecificationUrl $SwaggerfileUrl -Path "conference" -ApiId "conferenceAPI"

Deploying APIM with PowerShell Click for the final PowerShell-code

Conclusion

We used PowerShell to create an instance of API Management. As mentioned above, PowerShell is actually a great tool for working with API Management. But there are lots of other options to choose of when provisioning APIM.

Join Newsletter
Get the latest updates right in your inbox. I never spam!
Sven Malvik
Written by Sven Malvik

Latest Stories

Logging in Azure API Management

This post is a complete step-by-step guide on how to send logs from Azure API Management to Azure Event Hub with PowerShell. We start by ...

Apr 11, 2020

Event-Driven Infrastructure with App Configuration

Azure App Configuration is great for externalizing application configurations. But what if an application is our infrastructure? How coul...

Sep 12, 2020

Backup and Restore in Azure API Management

As infrastructure gets more complex, more parts will eventually break. This is even more true as we make frequently changes. Sometimes we...

May 02, 2020

Azure API Management with Terraform

Terraform is a popular tool for managing infrastructure resources. I counted about 120 supported providers. Azure is one of them. In this...

Apr 04, 2020

Understanding Policies in Azure API Management

Policies are the heart of Azure API Management. They let us change the behavior of our APIs in a very flexible manner. Before I dive in t...

Apr 18, 2020

Introduction to Azure API Management

Azure API Management (APIM) is a way to create consistent and modern API gateways for existing backend services. It provides an interface...

Jan 25, 2021

Azure API Management with REST

Today, we will provision Azure API Management by using Postman as an API client, sending plain web requests to Azure. We already provisio...

Mar 14, 2020

Serving Website Images from Azure CDN with SSL

In this post I will show you step by step how to serve images on a website from Azure CDN with SSL enabled. My blog has a couple of Azure...

Apr 25, 2020

How To Debug Policies in Azure API Management. A Step-by-Step Guide.

In this post I want to briefly go through the Azure API Management extension for VSCode and how we can debug policies. It’s one of the qu...

Jan 16, 2021

Azure API Management from the Portal

We will provision Azure API Management. Creating an instance of it is just a click in the Azure Portal. We’ll do it once to show how easy...

Mar 07, 2020

AZ-303 Self-Study Guide for Becoming an Azure Solution Architect

Microsoft updated it’s role based exam for AZ-300. It’s now called AZ-303 and launched last year. This certification is a great proof for...

Feb 01, 2021

Latest Stories

Logging in Azure API Management

Logging in Azure API Management

This post is a complete step-by-step guide on how to send logs from Azure API Management to Azure Event Hub with PowerShell. We start by ...

Apr 11, 2020

Event-Driven Infrastructure with App Configuration

Event-Driven Infrastructure with App Configuration

Azure App Configuration is great for externalizing application configurations. But what if an application is our infrastructure? How coul...

Sep 12, 2020

Backup and Restore in Azure API Management

Backup and Restore in Azure API Management

As infrastructure gets more complex, more parts will eventually break. This is even more true as we make frequently changes. Sometimes we...

May 02, 2020

Azure API Management with Terraform

Azure API Management with Terraform

Terraform is a popular tool for managing infrastructure resources. I counted about 120 supported providers. Azure is one of them. In this...

Apr 04, 2020

Understanding Policies in Azure API Management

Understanding Policies in Azure API Management

Policies are the heart of Azure API Management. They let us change the behavior of our APIs in a very flexible manner. Before I dive in t...

Apr 18, 2020

Introduction to Azure API Management

Introduction to Azure API Management

Azure API Management (APIM) is a way to create consistent and modern API gateways for existing backend services. It provides an interface...

Jan 25, 2021

Azure API Management with REST

Azure API Management with REST

Today, we will provision Azure API Management by using Postman as an API client, sending plain web requests to Azure. We already provisio...

Mar 14, 2020

Serving Website Images from Azure CDN with SSL

Serving Website Images from Azure CDN with SSL

In this post I will show you step by step how to serve images on a website from Azure CDN with SSL enabled. My blog has a couple of Azure...

Apr 25, 2020

How To Debug Policies in Azure API Management. A Step-by-Step Guide.

How To Debug Policies in Azure API Management. A Step-by-Step Guide.

In this post I want to briefly go through the Azure API Management extension for VSCode and how we can debug policies. It’s one of the qu...

Jan 16, 2021

Azure API Management from the Portal

Azure API Management from the Portal

We will provision Azure API Management. Creating an instance of it is just a click in the Azure Portal. We’ll do it once to show how easy...

Mar 07, 2020

AZ-303 Self-Study Guide for Becoming an Azure Solution Architect

AZ-303 Self-Study Guide for Becoming an Azure Solution Architect

Microsoft updated it’s role based exam for AZ-300. It’s now called AZ-303 and launched last year. This certification is a great proof for...

Feb 01, 2021