A Step By Step Guide On Developing Standard Logic App Using Visual Studio Code
Rajeshwaran K.
Solutions Architect Azure & Power Platform | IaC | Microsoft Certified Trainer
If you’re reading this, chances are you’ve already explored Logic Apps, most likely in the consumption-based model, and are now looking to transition to the standard Logic Apps. If that’s the case, you’re in the right place.
In this article, I aim to guide you through the process of running a Logic App locally using Visual Studio Code. I’ll also share some valuable insights, covering details that are often overlooked or assumed to be common knowledge in the official documentation, making your transition smoother and more efficient.
Prerequisites
Visual Studio Code
.Net Core SDK 6 or later
Setting up of Visual Studio Code
The following extensions are needed to be installed on your visual studio code: 1) Azure Account Microsoft
2) C# (Base language support for C#) Microsoft
3) Azure Functions Microsoft
4) Azure Logic Apps (Standard) Microsoft
5) Azurite Microsoft
It’s a good idea to check the settings for the extensions you have installed and adjust any that might be useful. The most important one for us is the Azure Logic App Standard settings. Make sure the “Auto Start Azurite” option is turned on, and that the default version of the Azure Functions runtime is selected. To access these settings, press Ctrl + Shift + X. You can also click the settings gear in the bottom-left corner of Visual Studio Code to get there.
A screenshot of the different sections we have/will use in the “Activity Bar” of the Visual Studo Code.
Note in my screenshot, I called out the wheel symbol on the activity bar as Settings. It is named as “Manage” when you hover the cursor over it. But it is that option that we need to use to go to settings.
Creating the Logic App in Visual Studio Code
The first step that we need to do in Visual Studio Code is to choose the Azure option option in the “Activity Bar”. Now you will see three sub-sections. The one you need to go to is called “WORKSPACE”.
In the workspace when you move your cursor over the “Create Function Project” you will see two icons — azure functions and the logic apps icons as shown below.
This because you have the extensions installed correctly. Now, click on the Azure Logic App icon and select “Create new project….” as shown below
You will be prompted to choose a folder. I used the “Browse….” option to navigate to and choose an empty folder of my choise called “helloworld” as shown below.
The next step is where it asks you to choose between a “Stateful Workflow” and a “Stateless Workflow”.
I recommend choosing stateful during learning as you can see the states. The stateless workflows do not store state so its not possible to analyze what happend in the logic app during failures.
Next step is to name your stateful workflow.
Then you will be prompted to choose to open in new window or stay in the same window. I choose to stay in the same window.
Now there will be some file created and you will be moved to the “Explorer” view of the activity bar. Then again you will be prompted to either choose “Use connectors from Azure” or “Skip for now”. I will choose the first option.
Since you decided to do this, now you need to decide to choose a subscription from your Azure tenant that your Visual studio code is connected to.
The next step is to choose an existing resource group or create a new one.
We will create a new one and therefore we will be required to name it. I will name mine as rg-we-helloworld. Then we will be prompted to choose the location for the resource group. I will choose west europe. And that is it. You must see that a resource group was created in the chosen location under the choosen subscription of your account. You can see this by going into your azure portal.
Note that even though the resource group is created in the cloud, you cannot see any resources underneath the same. That is because you are still developing locally. You visual studio code at this stage should look like the following.
Underthe explorer, beneath your project “HELLOWORLD” in the empty area, make a right click and choose "Convert to NuGet-based logic app project".
You will be prompted and you need to agree to move to a NuGet-based project.
And you can see that some new files got created.
Now we can start building the workflow. This can be done by right clicking on the “workflow.json” file and select “Open Designer” as shown below
Now we are going to a trigger “When a HTTP request is received”. This trigger enables the logic app to receive HTTP post via an endpoint url.
We will also add another step to it called the “Response” where we will write our message “Hello World” as response.
Now we need to click on save and try to find the workflow url. The workflow url is the callback url found in the “Overview” of the workflow.json. For this we need to right click the workflow.json and click on “Overview”.
Note that you may experience that you do not have the possibility to choose the “Overview” or “Open Designer” options and this is most probably because the workflow.json file is not open and highlighter in your editor. Open the file by docuble clicking it and then you can right click for more options.
When you open the overview, you can see that you get a message “Please start the project by pressing F5 or run it through the Run and Debug view”.
So let us press the F5.
There is a chance that you may not see the call back url still. This is because of an ACL issue. You need to use the following command and run it on a powershell terminminal.
Note, in short, this command reserves the URL https://localhost:7071/ for all users (Everyone) on the local machine, allowing any user or service to listen on port 7071 (the default HTTPS port) for incoming HTTP requests on localhost.
Now close and reopen the “Overview” and you must see the call back URL.
Note that you are able to see the “Azurite” that you installed also starting and running the queue and the blob service and providing an environment of the same in the local machine.
Now we can use this callback url on a tool like SOAP UI and make an HTTP call as shown below.
You can see the response message “Hello World” that we set on the Response step of the workflow.
Deploy to Azure
Now that we have a working logic app, let us deploy it to Azure.
To deploy, go to the Azure icon on the activity bar and click on the azure logic app icon from the workspace area and choose the option “Deploy to logic app….”.
You will now need to choose a subscription. Choose the one you used earlier. Now you need to choose if you want to create a new standard logic app in azure or use an existing one. Lets create a new one. Give it a name. I will call mine “logic-we-helloworldmessage”. Choose the location which preferably should be the one where you created you resource group.
This is not mandatory but our idea was to deploy the logic app in that resource group and hence I will create it there. Next you will be prompted to choose the logic app hosting plan. Lets choose “Workflow Standard”.
Now we need a new app service plan. You can also choose one you already have if you would like. I will create a new one and give it a name.
Lets take the cheaper and simpler one which is the “Workflow Standard”.Then it will ask you to create an app service plan and give it a name.
After you give it a name it will ask you to choose the workflow standard. Lets choose WS1.
We will not choose a redundancy zone. Finally we will choose the resrouce group we already created. This will start creating the logic app standard and all its required components in the resource group. You can see the status of the same in the visual studio code under the Output section as follows.
Since the deployment says it has succeeded, lets go to the azure portal to see what resources it has deployed in Azure.
You can now run the logic app from the Azure portal. For this we need to open the logic app and navigate to the workflows and open the workflow we need to run.
Since this is an “When an HTTP request is received” trigger, there is an option to run the workflow using the “Run” button as shown below.
On running the same, you can see that an entry for the run is created with a run id.
You can go inside the run id and see the different steps that executed and also the input and output values on each of the logic app steps as shown below.
Note that you can always make more changes in your local version of your logic app and deploy the same to cloud version following the same steps. You can also use ngrok to allow different team members to test the local version of your logic app if such a use case arises. This ensure that the cloud version of the logic app remains as it is before your changes are tested ok to be deployed there.
In my next article, I would try to cover the part where we use terraform to deploy all the infrastructure components of the logic app using an azure pipeline. I will also cover that the changes in the workflow are also delivered via Azure pipelines and subsequently to the different environments. If you are interested, please follow me on medium.
Awesome with Security + AI ?? Senior Security Architect @ Not Bad Security. Microsoft MVP, MCT and MCM. Ctrl+Alt+Azure Podcast.
2 个月Nice writeup!