Category Archives: Azure
Deploying resources using Azure Resource Manager (ARM)
Azure Resource Manager is a management platform for Azure resources. It enables you to deploy, manage, and monitor resources on Azure, including virtual machines, web apps, and SQL databases. Some key features of Azure Resource Manager include: Resource groups: You can use resource groups to group related resources together and manage them as a single unit. Templates: You can use Azure Resource Manager templates to deploy and manage resources consistently and predictably. Templates are written in JSON and allow you to define the infrastructure for your application. Role-based access control: You can use Azure Resource Manager to set fine-grained permissions on resources so that only authorized users can access them. To use Azure Resource Manager, you can use the Azure portal, the Azure Resource Manager APIs, or the Azure CLI. Resource providers: Azure Resource Manager works with resource providers to create, manage, and delete resources. Each resource provider offers a set of resources that you can use, such as virtual machines, storage accounts, and databases. Resource Manager model: Azure Resource Manager uses a declarative model, which means that you define what you want your resources to look like, and Azure Resource Manager takes care of creating and configuring them for you. This is in contrast to an imperative model, where you have to specify the exact steps to create and configure a resource. Locking resources: You can use Azure Resource Manager to lock resources to prevent accidental deletion or modification. This is useful if you have resources that are critical to your application or business. Auditing and tagging: You can use Azure Resource Manager to audit changes to resources and to apply tags to resources for the organization and cost management.Example of an Azure Resource Manager template that creates a virtual machine: I hope this helps!
Share Story :
Backup Azure DevOps Git Repositories
Here we will see how to backup the repository using the YAML file. This includes the following steps Create an Azure DevOps Personal Access Token (PAT) Create a YAML file Create Subscription Connection Create an Azure DevOps Personal Access Token (PAT) Step 1: Sign in to your Azure DevOps Portal Step 2: Go to Personal Access Token Step 3: Create a Token by clicking on “New Token“ Give it a name Select the “Read” checkbox to fetch the repository Click on Create Note: Copy and Save the token as you will not be able to see it again Create a YAML Pipeline Step 1: Go to Pipelines Step 2: Choose Azure Repos Git Step 3: Select your repository Step 4: Configure it as a starter Pipeline Below is the default code you will see. Trigger: The wildcard (*) will monitor all the branches, the pipeline will be triggered whenever you have any changes in your repository CmdLine: The command calls “git clone –mirror ” to make a copy of your repository. PAT needed to be used while fetching a repository Archive Files: It will take the git repository which was cloned in the previous step and then zipped to “Backup.zip” File Copy: It will take the archive copy and send it to Azure Blob Storage Creating a Subscription Connection Step 1: Go to Project Settings Step 2: Go to Service connections Step 3: Click on New service connection Step 4: Choose Azure Resource Manager Step 5: Select Authentication Method as Service Principal (automatic) Note: Make sure to use the same credentials to login to DevOps as in Azure Portal Step 6: Subscription will be chosen automatically. Give it a name Select a resource group where you have your storage account Then save Step 7: Use the connection name in YAML. Save and Run It will create a Job See the status of the Job After Job gets completed, you will see a zip file in your blob
Share Story :
Import an API and all its operations using its documentation in Azure API Management
Most of the time you would need to import an entire API collection with all of its supported operations to mask all of them or set policies on them. This can be easily done using Azure API management service. To start, log in to your Azure Portal, head over to the API management resource, and go to the API section on the left. From the options, select OpenAPI definition. Here I will use the Pet store API, https://petstore.swagger.io/ Go to the site or the site where your API stores the collection of all supported operations in JSON format. You can either have the JSON file of the collection or a website. In the OpenAPI specification put the link to your JSON collection or upload the JSON file and fill in the rest of the details and click on the Create button. You can see the list of operations appear. Hope you enjoyed this blog!
Share Story :
Mask your APIs using Azure API management
Most of the time you don’t want to show the original API URL or want to hide the original URL for security purposes in your code. This can be easily achieved if we assign this original URL to some other URL so end users can’t find out what’s the original API. So let’s see how this can be achieved. First, log in to your Azure Portal. Search for Azure API management service and create a new resource. Select the desired azure region and resource group. Give a unique name for this resource as the API URL will be based on this. For testing purposes set the Pricing tier as Developer. Proceed through the rest of the options as default and create the resource. Make sure to grab a coffee as the deployment takes around 45 minutes to 1 hour and you will see this screen only. When the deployment completes, you will receive an email, alerting you that the process is complete. Click on ‘Go to resource’ from the Deployment screen. You can find the new URL by getting inside the resource. Now let’s add a sample API so that we can mask it. In this case, I will use https://catfact.ninja/fact this api gives us random facts about cats. Go to the API section on your API management resource. Select the HTTP option, so that we can manually define this API and fill in the details Now save this API, you can see it on the left pane. Next, we have to add an operation for this API. Select GET operation and place the request to the main URL. In this case, the request was /fact We can test this API through the test tab and as you can see it’s working. Now we will use the main URL which will be used to mask the original API. As you can see this is not working. This happens as each API needs to be bound with a product. Go through the Products section and choose unlimited. ‘Starter’ has a rate limit of 5 calls per 60 seconds, The ‘Unlimited’ policy does not have this limitation. Click on ‘Add API’. Select your API. You will get a notification saying the API has been added to a product. Now to view this API we need a subscription, head over to the settings section on the left pane, disable the required subscription option, and then save it. Now again hit our main API through a browser, as you can see it’s working. I hope this blog helped you 🙂
Share Story :
Create and deploy your first Azure Function using Visual Studio
In my previous blog, we created and deployed an Azure function using the Azure Portal itself. Now In this part of the blog, we will see how we can create and deploy Azure Function using Visual Studio. To proceed you would need ASP.NET and Azure Development extensions installed on top of your Visual Studio. If you haven’t had these installed you can go to Apps and features on your device and modify the installed program by selecting the change option instead of Uninstall. After installing these extensions, Create a new Project and search for Azure functions. Give the Project any desired name. Set the trigger for the function as HTTP. A sample piece of code will get loaded. In this scenario, I will modify the default code and write my custom logic, which adds two numbers. To run this logic, press F5 button on your keyboard and copy the URL, hitting this URL will trigger our function. Paste and run this URL in a web browser. As you can see on hitting the URL the function gets triggered and our two numbers get added in the output. Now we have to publish our function, it’s been working amazingly. Right-click on the Project Name and click on the Publish button. Select the target as Azure. Select Specific Target as Azure Function. Select the desired Function app instance or create a new one. Click on the final publish button. Wait for the function to successfully get deployed. Now we will check this in the Azure Portal and trigger it from there, Log in to the Azure account. You will find the recently deployed function in the left pane in the Functions section. Open this function and get its URL. Paste and run this URL in a web browser. You can see the output. Hope you understood the process of deploying serverless Azure functions using Visual Studio. Have a great day!
Share Story :
Create your first Azure Function using the Azure Portal
Learning serverless Azure Functions and deploying them, might sound like a daunting task. Azure functions are one of the most essential features of Microsoft Azure. In this article, we will see how we can create and deploy our first function using Azure Portal itself. In the next blog, I will also demonstrate how we can publish functions using visual studio. To start, login into your Azure Portal. Search for the Function app and click on create. Select desired resource group, give your function app a unique name, and fill in the rest of the options as required. After the deployment completes, open the resource. Go to the functions section on the left-hand pane. Click on the Create button. Select the “Develop in Portal” option as we are using Azure Portal to create our function. And select “HTTP trigger” now as we want to trigger the function using its API. Go to the “Code+Test” option, you’ll find a sample code. Change values in it for a personal response. You can also change the logic of the code from default. Here I am passing my name as Body in the request (input) section. As you can see based on the request body I have received a personified response. You can use the get function URL option and display desired output on hitting the URL. The output section in the default code is the last line “return new OKobjectResult(youroutput);” Hope you learned to deploy a function using the portal from this blog. Have a great day!
Share Story :
CI/CD Pipeline using YAML file
This is blog is intended to share information about creating a CI / CD Pipeline using YAML file. Case Study Create a CI/CD pipeline using YAML for a web application So, let’s start with lets creating a project Use cmd to create a project and then bind it to a solution Create Solution dotnet new sln -o Test_CI_CDPipeline Then change the directory cd Test_CI_CDPipeline Then create a Web Project inside Test_CI_CDPipeline dotnet new mvc -n Test_CI_CDPipeline Now bind the project to solution dotnet sln HelloWorldApp.sln add HelloWorldApp.Web\HelloWorldApp.Web.csproj Need to restore all the dependencies dotnet restore Now, build the solution. Do not restore dependencies while we are building the solution. dotnet build –no-restore –configuration release Publish the solution dotnet publish –no-build –configuration release. Now a project is created, built, and published on local Machine. The aim is to achieve the same using a continuous integration pipeline. For this one need to have an Azure DevOps account. In that, create an organization (if not created already) and then create a project. You can either create a private project or a public project. Before that, one needs to initialize git in the location machine. Go to the working folder (location of the location file). Initiate the git git init The purpose of git is to host the source code. Ensure that binaries created while building a project should not be included. For this add gitignore file to the project. Now, you need to stage all the content git add . Commit the content git commit -m “—Name-it—” Now you can push this to the Azure DevOps repo. Copy and paste the command and everything from the local machine will be pushed to Azure Repo. Create Pipeline Go to Pipelines on the Left panel and click on Create Pipeline. It gives two options YAML or Classic editor. Select Azure Repos Git (YAML) as it will be used to push the local project in further steps Select the project created earlier Select the type of project you are creating After this, you will see a YAML file. Here one needs to edit the file and make changes as per the need. Below is a sample code Trigger: specifies which branches cause a continuous integration build to run Pool: specifies which pool to use for a job of the pipeline. A pool specification also holds information about the job’s strategy for running. Steps: specifies a list of tasks that need to be run Task: specifies commands/tasks that need to perform to achieve a build file. Build the project first Publish the Project Publish it as an Artifact Click save and run. Below shows the artifact created Now, this artifact needs to be consumed by an Azure website. For this, one needs to create a web application. Create an app service for that in the Azure portal. We need to create a service connection to connect Azure resource. Go to Project Setting, then service connections Create a New connection and select Azure Resource Manager Choose Automated (here you need to login with the same credentials that you use for the Azure portal) and click next Choose the subscription and Resource group. Give a name to the connection Now, proceed with creating a release pipeline Select the template you want to use and then apply. Choose the artifact from where you want the files to be picked up and click add Click on Job to a stage Add your Azure subscription, select the app service you have created, and save it. Then click on Create release Click on Deploy Once you are done deploying, click on the URL from the App service
Share Story :
How to import an already existing Logic App Template in Azure Logic App
If you earlier have exported a Logic app template for further use and deleted that logic app, then below are the steps to import an already existing Logic app template as a Logic app. Go to https://portal.azure.com and then to the Logic app. Open any Logic app. For example, I took the below logic app. Go to Export Template. Click on Deploy Click on Edit Template Click on Load File. Select the template you want to import. Change the name to whatever you want. Here I will keep it as it is and Copy the name for further use. Copy the Name and click on Save. Check this page if it’s the same name and resource group as desired. Click on Review and Create. And then again, click on Create to create the Logic app. Now the Logic app template is imported and ready to use. I hope this was helpful.
Share Story :
Secure your Environment Variable inside Azure Function using Key Vault
In the previous blog, we learn about how to use the Environment variable in Azure Function. Environment variables are most important and confidential as they might contain the system credentials or configure that you don’t want any to access directly. The most unsecure way to store them is directly inside the Configuration of Azure function so in this blog we will see how to store the Environment variable inside the Key Vault and use the Key Vault reference in Configuration. You can create an Azure function and use Environment Variable to do so do refer to my previous blog: Step 1: Create a Key Vault Login to Azure Portal and click on + Create a resource called “Key Vault”. Click on Create You can create a new resource group or select the existing group based on your preference. (You can create all resources related to a single project in one resource group so that it will easier to manage resources project wise) You need to set up the Access policy during the creation or after creating the Key Vault. We will set up an access policy for Azure Function later in the blog. Step 2: Set an Access policy for Azure Function. Open the Azure Function in which you want to use the reference of Azure Key Vault. Navigate to Identity Tab and toggle System assigned status to “ON”. Copy the Object (Principle) ID as we are going to use it during adding access policy. Open Azure Key Vault and Navigate to the Access Policies section. Click on + Add Access Policy We will only Add Get Permission in the Secret permissions section. You need to only add the permission that you want to allow your Azure Function can perform. Select the Principle User. Copy the Copied “Object ID” into search it will be easier to find it. Click on Add. Once you will add a resource in the access policy, it will allow your resource (Azure Function) to perform a Get operation on all the secrets from Key Vault. Do not forget to Save after you add the policy. Step 3: Add Secret and Configure it inside Azure Function Navigate to the Secrets section and Click on + Generate/Import Enter the Name and Value(Credentials/Configuration) Open the current version and Copy the secret URL as it will be required while configuring the Reference. Navigate to the Configuration section of Azure Function. Change the Configuration and add the KeyVault Reference as below: @Microsoft.KeyVault(SecretUri=<Copied SecretURL>) Do not forget to Save after changing the configuration Step 4: Testing using Postman We will require the API testing tool, here I am using Postman and the following is the link to download “Postman”. https://www.postman.com/downloads/ Copy the Function URL and send a post request. As result, you will notice the username is coming from KeyVault as we have to change the configuration. Conclusion: This is how you can secure your Environment Variable using Azure KeyVault. You can set up multiple KeyVault for different deployment and access policies depending on the requirement. When you are storing the Credentials and Configuration in KeyVault, you just need to set up the Access policy. All configuration is managed by the Azure Admin and if origination has a policy that they don’t want to share the credentials they can follow this process and only share the KeyVault URL with the developer so that they only need to configure it.
Share Story :
How to call logic app in Azure function app
In this blog, we will see how we can trigger the logic app using the azure function app. Let’s start with creating a logic app (HTTP triggered) that sends an email when the logic app URL is hit in the function app. Step 1: Create a logic app resource and start by adding an HTTP GET request trigger. Url will auto-generate after saving the logic app. Step 2: Add send email block after that to receive an email Step 3: now create a function app in visual studio by creating a new project. Step 4: Add project name and now select type of function app, select the create option Step 5: Add the below code to the auto-generated code template in the visual studio Step 6: Run the function locally. then you will get URL in the command prompt copy that and paste it into your browser. Step 7: After entering the URL you should receive an email as mentioned in the logic app. In this way, the logic app triggered successfully using the function app Hope this blog helps you. Thank you!!