Highly Scalable Application: Logic App, Cosmos DB, and APIM

In this post, we will create a scalable registration application using Logic App and will store the data in the NoSQL database (Cosmos DB), which will send the email notification. The application will be secure by Azure Active Directory (AAD) authentication.

High-level step

  1. Create a Logic App
  2. Create Cosmos DB and Collection
  3. Configure Logic App to write data to Cosmos DB.
  4. Configure Logic App to send an email notification.
  5. Create APIM – multi-reason
  6. Import Logic App to APIM

Create Logic App

Logic App is an Azure app service that helps to design and automate a business process, workflow, system integration, and enterprise integration for both cloud and on-premises. Here, we are going to create a Logic App application that will accept an HTTP request from the user.

  1. Click All Services and search for Logic Apps, and click on it. In the new window click on Add Logic Apps.
  2. Specify the following parameters and click on Create.
    • Name: Demo-logic app
    • Resource group name: Demo-RG
    • Location: West Europe
  3. Select the newly created Logic App and click on the Logic app designer, and then click on Blank Logic App.
  4. Search for ‘HTTP request‘ then click on When an HTTP request is received under Triggers.
  5. Click on Use sample payload to generate a schema.
  6. Paste the below code and click on Done to generate JSON.
  "id": 101,
  "firstname": "Sakaldeep",
  "lastname": "Yadav",
  "email": "abc@demo.com",
  "org": "Demo",
  "source": "erb"
  1. The JSON code has been generated as below. Click on New Step.
  2. Search for ‘response‘ and select Response under Actions.
  3. Select the below parameters.
  4. Verify the headers and click on Save.

Now Let’s test if the Logic App is receiving the HTTP request and responding to it. We can many tools to use this such as postman. Here we use Azure CLI Cloud Shell.

  1. Click on Cloud Shell as shown below and run the below commands.

Copy the HTTP POST URL as shown below, this will need to run the Curl command. First, assign the URL to the variable called endpoint and then run the curl command.

curl -X POST $endpoint   --include   --header 'Content-Type: application/json'   --data '{
    "id": 101,
   "firstname": "Sakaldeep",
  "lastname": "Yadav",
  "email": "abc@demo.com",
  "org": "Demo",
  "source": "web"
  1. Click on Overview and we can see the logic app has run successfully. Click on Succeeded.

  2. We can see the logic app has received the HTTP request.

  3. It has responded as specified.

The logic is working as expected. Now we need to store the data in the database permanently. Now we will create Cosmos DB and then write data into it.

Create Cosmos DB and Collection

  1. Click All Services and search for Cosmos DB, and click on it. In the new window click on Add.

  2. Select Basic and specify the following parameters and click on Create.

    • Account Name: skldemocosmosdb
    • API: Core(SQL)
  3. The Cosmos DB has been created, and now we have to create a Database and Collection to store the data.

  4. We will create a database using Azure CLI. Navigate to the CLI and run the below command.

az cosmosdb database create    --name "skldemocosmosdb"    --db-name "myDatabase"    --resource-group "Demo-RG"
  1. Run the below command to create a collection.
az cosmosdb collection create    --collection-name "Container01"    --name "skldemocosmosdb"    --db-name "myDatabase"    --resource-group "Demo-RG"    --throughput 400
  1. The database and collection have been created.

  2. Copy the URI of cosmos DB, we will need this URI in the logic app to integrate the logic app into the cosmos DB.

  3. Again switch to Logic App and click on New Step and search for Condition. Select Condition under Actions.

  4. Add the condition as shown below. Here, we are putting a condition on ’email’. Every email address must contain ‘@’ so we are putting the condition on this. If the email address contains ‘@’, it means the registration has been done and written to the database.

  5. Search for Cosmos DB and click on Crate and Update Document under Actions.

  6. Paste the URI in Connection Name, select CosmosDB Account and click on Create.

  7. Select Database ID and Collection ID from the dropdown. Specify the parameters in Documents.

  8. Switch to Cosmos DB and verify the data has been written to the collection.

    Cosmos DB configuration has been completed, now we will need to send an email notification.

Configure Logic App to send an email notification

  1. Click on New Step to configure email notification.

  2. Select Office 365 Outlook. You can use any account as Gmail.

  3. Click on Send an Email under Actions.

  4. Sign in to the Office 365 account.

  5. Specifies parameters as shown below.

  6. The email has been received.

    Save the logic App and run the curl command again.

  7. Data has been written to the database again.

Create APIM (API Management Services) and Import Logic App

  1. Click All Services and search for API Management Services, and click on it. Click on Add to create an APIM instance.

  2. Specify the following parameters and click on Create.

    • Name: SKL-Demo-APIM
    • Organization name: Sakaldeep
    • Pricing Tier: Developer (NO SLA)
  3. Deployment is in progress.

  4. Deployment completed.

  5. Select APIs and click on Logic App.

  6. Click on Browse and select the logic app.

  7. Click on the demo-logic app that we created earlier.

  8. Click on Create.

  9. The logic app has been imported into APIM and we can access it from https://xxx.azure-api.net.

Hope this post is informative.