Author - Tao Yang (TY Consulting Pty. Ltd.)
Copyright - (c) 2017 TY Consulting Pty. Ltd. All rights reserved.
This folder contains the deployment artifacts for an Azure Functions demo app. This demo app allows users to cast vote using a HTTP GET request (i.e. by hitting an URL from browser, or scanning a QR code from mobile devices). In this demo, users can vote how much they love the famous Australian food Vegemite (https://www.youtube.com/watch?v=P_sUhTWtvG4)
Note: This demo was originally developed for Pete Zerger and Tao Yang's Experts Live Australia 2017 presentation Cloud Automation Overview. In the presentation, the attendees voted by scanning the QR codes from a slide like this:
This demo app is made up using the following Microsoft cloud based services:
When the Azure Function is triggered via HTTP request, it performs the following steps:
The vote result can be accessed by either querying the Azure SQL database, or via a Power BI report that is connected to the Azure SQL database.
Most of the components are deployed using the PowerShell script Deploy-VotingApp.ps1. This PowerShell script performs the following actions:
After executing the Deploy-VotingApp.ps1 script, you will need to manually create Power BI report (based on the report provided in this repository).
The following PowerShell modules are required to execute the Deploy-VotingApp.ps1 PowerShell script:
All of these modules can be found from the PowerShell gallery (https://www.PowerShellGallery.com), can be installed using command Install-Module [Module-name] -Force on computers running Windows Powershell version 5 or later.
Azure AD and Subscription PrivilegeYou will need to specify a credential for a user that has admin privilege for Azure AD tenant and Azure subscription.
Executing Deploy-VotingApp.ps1 ScriptBefore running the script, make sure you update variables from line 283 to 295 according to your environments
Syntax:
.\Deploy-VotingApp.ps1 $(Get-Credential)
When prompted, specify your Org Id that has admin access to both Azure AD tenant and Azure subscription.
The script takes approximately 10 minutes to execute. Once completed, you are able to see the following components in the resource group that you have specified (the names will be slightly different.) Azure Resources:
The QR code images are saved to the $PSScriptRoot folder (same folder of the deploy-votingapp.ps1 script):
To better understand the architecture, you may choose to manually provision the components required for this voting app:
CREATE SCHEMA [AzureFunctionDemo] AUTHORIZATION [dbo] CREATE TABLE AzureFunctionDemo.Rating ( Id int PRIMARY KEY NOT NULL IDENTITY(1,1), RatingScore int NOT NULL, RatingTitle varchar(10) NOT NULL ) CREATE TABLE AzureFunctionDemo.Vote ( Id int PRIMARY KEY NOT NULL IDENTITY(1,1), RatingId int NOT NULL, ClientIP varchar(128) NOT NULL, SubmissionDate datetime NOT NULL, FOREIGN KEY (RatingId) REFERENCES AzureFunctionDemo.Rating(Id), )
INSERT AzureFunctionDemo.Rating (RatingScore, RatingTitle) VALUES (1, 'Awful'), (2, 'So So'), (3, 'Love It')
Create a new read-only SQL login & user called 'SQLReadOnly' for Power BI report
Creating new login:
IF NOT EXISTS (SELECT * FROM sys.sql_logins WHERE name = 'SQLReadOnly') CREATE LOGIN SQLReadOnly WITH PASSWORD = 'specify-your-password'
Create new database user:
IF NOT EXISTS (SELECT * FROM sys.sysusers WHERE name='SQLReadOnly') BEGIN CREATE USER SQLReadOnly FOR LOGIN SQLReadOnly WITH DEFAULT_SCHEMA = dbo; END IF is_rolemember ('db_datareader', 'SQLReadOnly') <> 1 BEGIN EXEC sp_addrolemember N'db_datareader', N'SQLReadOnly'; END
{ "frameworks": { "net46":{ "dependencies": { "Microsoft.IdentityModel.Clients.ActiveDirectory": "3.13.1", "Microsoft.IdentityModel.Logging": "1.0.0", "Microsoft.Azure.Common": "2.1.0", "Microsoft.Azure.KeyVault": "1.0.0", "System.Data.SqlClient": "4.3.0" } } } }
Generate QR code for different votes
Aweful: [function URL]&rating=1
So So: [function URL]&rating=2
Love it: [function URL]&rating=3
Note: There are many free websites you can use to generate QR codes. Or you can use the QrCodes PowerShell module mentioned above to generate the QR code images.
Write-Output 'Generating QR Codes...' Out-BarcodeImage -Content $awefulURL -BarcodeFormat QR_CODE -Path 'C:\Aweful.png' -ImageFormat png -Width 500 -Height 500 Out-BarcodeImage -Content $SosoURL -BarcodeFormat QR_CODE -Path 'C:\Soso.png' -ImageFormat png -Width 500 -Height 500 Out-BarcodeImage -Content $LoveItURL -BarcodeFormat QR_CODE 'C:\LoveIt.png' -ImageFormat png -Width 500 -Height 500
Create Power BI report using your favourite visuals. Use the SQL Read-Only user name and password to connect to SQL DB. You can use the following SQL Query in Power BI report:
Select v.Id as VoteId, v.RatingId, r.RatingTitle, v.ClientIP, v.SubmissionDate from AzureFunctionDemo.Vote v JOIN AzureFunctionDemo.Rating r on v.RatingId = r.Id
To cast votes, end users can either browse to various URLs in the browser or scan QR codes using mobile devices. For the demo environment, the URLs and QR codes are listed below:
URLs:
QR Codes:
You may use the Power BI report provided in this repository and import it to your Power BI account.
Importing Power BI reportTo import the Power BI report, firstly you will need to retrieve the SQL Read-Only account credential from key vault. To access the secrets, you may need to give yourself access in the key vault:
Once the read-only user credential is retrieved, you need to open the Power BI report in Power BI desktop and modify the connection
Once the report is loaded, you can publish it to Power BI Online.
Other Integration OptionsNote: This report uses direct query, however, cache refresh is scheduled to run every 15 minutes. you may need to wait up to 15 minutes after voting in order to see the change reflected on this report.
The author of this app has also managed to create several Microsoft Flows to trigger the function using Flow buttons. The setup is very straightforward:
In this sample app, we have demonstrated how to securely integrate Azure Functions with other Azure services such as Azure SQL DB using Key Vault. We have also demonstrated how to trigger the function from mobile devices using QR codes and MS Flow.
In this project, several components come from other community projects:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4