niusnet / serverless-url-shortener-azure

Serverless URL Shortener on Azure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serverless URL Shortener on Azure

This is an example implementation of URL Shortener using Serverless technologies in Azure. Check out the accompanying blog for the details about the implementation.

Prerequisites

  • Active Azure Subscription

  • Azure AD permissions to create RBAC Role, CosmosDB, API Managment, Azure functions, Storage Account, Azure Front Door, and other dependent services

  • Ability to login to Azure using browser

  • Latest version of Azure CLI and Azure Function Core Tools installed

  • Python version 3.9+ installed and create a Virtual environment to execute the deployment script

  • Existing Azure AD B2C tenant (Step by step guide can be found in this documentation)

    • Create 2 app registrations for Single Page Application (SPA) and API
    • Create a Sign Up and Sign In user flow

Repository content

  • config.yaml - Configuration file which you need to update to provide the required parameters
  • deploy.py - Deployment script which will deploy this solution in your Azure Subscription
  • url-shortener.bicep - Bicep template which creates required infrastructure in Azure
  • main.bicep - Main Bicep template which creates a new Resource Group and create the resources from the url-shortener module
  • function_code - Azure Functions source code to create short URL
  • index-template.html - HTML template for the Single Page Application (SPA) which will be updated with appropriate values deployed by Bicep

Configuration

You need to update the config.yaml with appropriate values for the deployment script to deploy the right resources.

Parameter name Description Example
environment Name of the environment prod
location Azure region where the solution needs to be deployed westeurope
subscription Azure Subscription ID where the solution needs to be deployed 7example-abcd-1234-pqrs-examplec5db2
aadB2cOrg Azure AD B2C Tenant Name suruku
aadB2cUserFlow Azure AD B2C User Flow Name for Sign Up and Sign In B2C_1_us_sisu
aadB2cApiClientId Azure AD B2C App Client Id of API bexample-abcd-1234-pqrs-examplef9a45
aadB2cSpaClientId Azure AD B2C App Client Id of Single Page Application (SPA) fexample-abcd-1234-pqrs-example6cd6a
shortUrl URL that should be used for shorterning (Include https:// and the training slash/) https://suru.ku/
writeScope Write scope for API in Azure AD B2C https://suruku.onmicrosoft.com/shorten-url/API.Write
readScope Read scope for API in Azure AD B2C https://suruku.onmicrosoft.com/shorten-url/API.Read

Deployment

Make sure you have cloned the repository and navigate inside the repository directory. If you haven't already created a python virtual environment, create one as the deployment script requires a virtual environment and activate it.

After updating the config.yaml run the following command to deploy the solution

python deploy.py

Review the prompts and confirm the subscription ID to start the deployment. Once the deployment has been completed you should add the following URI ([Your Short URL]/url-shortener/index.html - e.g. https://suru.ku/url-shortener/index.html) in redirect URI section of SPA app client registration in your Azure AD B2C tenant. In case if you don't have a domain and just want to test the solution you can use the Azure Front Door endpoint URL in the redirect URI (e.g. https://us-cdn-ep-example-babcdbdxyzb1234q.z01.azurefd.net/url-shortener/index.html). Front Door endpoint URL will be printed after the successful deployment of the above script.

About

Serverless URL Shortener on Azure

License:MIT License


Languages

Language:Bicep 52.5%Language:Python 24.4%Language:HTML 23.1%