Azure Tips and Tricks
Azure Tips and Tricks
azuredev.tips
ISBN 978-1-7327041-2-1
www.dbooks.org
Introduction
Hi, folks!
When I reflect back on Azure Tips and Tricks a year ago, I was only thinking that I’d write
a couple of posts and move on. Fast-forward to today, the collection has grown to over
150+ tips, as well as videos, conference talks, and now an eBook spanning the entire
universe of the Azure platform. What you are currently reading is a special collection of
tips based on page views of the entire series over the last year. I’ve grouped the top tips
and landed on four categories that cover web, data, serverless, and productivity. Before
we dive in, you’ll notice my pixelated form as you turn each page.
These represent:
• Blog - azuredev.tips
• Videos - videos.azuredev.tips
• eBook - ebook.azuredev.tips
• Survey - survey.azuredev.tips
Thanks,
Michael Crump (@mbcrump)
www.dbooks.org
Table of Contents
1 WEB
3 SERVERLESS
2 DATA
4 PRODUCTIVITY
WEB
If you’ve used Azure, you’ve more than likely used Azure App
Service to easily host web applications, REST APIs, and mobile
back ends. In this set of tips, I’ve pulled out the top 6 tips since the
creation of Azure Tips and Tricks for Azure App Service. They include
easily working with files in the console, easily setting up staging
environments and swapping between them, and routing traffic to
different versions of your app to “Test in Production”. I’ll also cover
how you can implement performance testing, best practices for
App Settings in Azure App Service, and cloning a web app that is
especially helpful if you have customers all over the world.
www.dbooks.org
Working with Files in Azure App Service
As you can tell from the screenshot, I start in D:\home\site\wwwroot. I can type dir to see a
current directory listing.
I can do basic commands here and even use TYPE <FILENAME> to parse
the output of a file to the screen. You can make directory and so forth, but
keep in mind that this is a sandbox environment and some commands
which require elevated permissions may not work.
Quick Tip You can
type help from the
console window for
a list of available
commands.
www.dbooks.org
A VS Code Experience to an Azure App Service
www.dbooks.org
Test Web Apps in Production
with Azure App Service
We’ll take a look at the files inside an Azure App Service
web site and how you can easily work with them.
www.dbooks.org
Give it a couple of minutes until you see that it has completed
pulling down your code from Git and then go to the new URL of
your site. You can find the URL on your overview page. In my case
it is, http://myquizapplication-staging.azurewebsites.net/
Great! Now keep in mind that we have two versions of our site:
one that is production and one that is staging. They are identical
except for the staging site has a large font that says jsQuizEngine
version 2.
www.dbooks.org
Success! It works, but what happens when they leave the site? We actually store a cookie
that keeps track of it. You can find this cookie yourself by inspecting the site and looking for
the cookie shown on the next page.
You could actually force the old production site by setting the
x-ms-routing-name cookie to self or providing it in the URL
query string such as http://myquizapplication.azurewebsites.
net/?x-ms-routing-name=self You could even use the URL to let
your users test different versions of your site. For example, I could
use http://myquizapplication.azurewebsites.net/?x-ms-routing-
name=staging to let users try my new website before I push it live.
This is very neat stuff, folks!
www.dbooks.org
Load Testing web apps with
Azure App Services
Load Testing allows you to test your web app’s performance
and determine if your app can handle increased traffic during
peak times. You can find this tool by logging into your Azure
account, going to your App service that you created, and
looking under Development Tools.
www.dbooks.org
Open or create your ASP.NET MVC app and modify the
appSettings section of the web.config file to add our
Environment key/value pair as shown below:
If you run the application locally, then you’ll see Production as it is coming from the
web.config file, but if you run it inside of Azure, then you’ll see Staging as it is coming
from the Apps Settings configuration store located in Azure. Neat stuff!
Connection Strings vs. App Settings You may have noticed Connection
Strings right below the App Settings option and wonder when to use it. A
general rule of thumb is to use Connection Strings for database connection
strings and App Settings for key/value pair application settings. If you
examine your web.config file, then you’ll see there is also a section for
connectionStrings just as there is a section for appSettings.
www.dbooks.org
Open it and
you’ll see the following:
www.dbooks.org
What is a Azure Resource
Manager again? Azure
Resource Manager enables
you to work with the resources
in your solution as a group.
You can deploy, update, or
delete all the resources for
your solution in a single,
coordinated operation. You
use a template for deployment
and that template can work for
different environments such as
testing, staging, and production.
Resource Manager provides
security, auditing, and tagging
features to help you manage
your resources after deployment.
Aka.ms/azuretips/
appservdeploy
www.dbooks.org
Configure a Backup for your
Azure App Service and Database
Most folks don’t realize how easy it is to configure a backup copy of your
Azure App Service to ensure you have restorable archive copies of your
app and database. In order to take advantage of this, you’ll need to log
into your Azure account and go to your App Service that you created. Look
under Settings and you will see Backup.
www.dbooks.org
Next, you’ll want to make sure that Scheduled backup is set to On. You’ll
want to configure the Days and Hours and then the current schedule that it
should back up from. I set mine to back up every seven days, and starting
from now. You’ll also want to set the retention and by default it will keep at
Once completed, least one backup. If you have a database, then you can also add it with just
you can click a checkmark.
on the backup
and see a Once everything is set, you can see that the next backup is configured and
feature called can either force it manually or restore from an existing backup with just a
Snapshot which visit to the Azure Portal. You typically want to use “manual” restore when
automatically you want to look at your backup at the current point in time vs “restore” a
creates periodic backup at a different time that occurred in the past.
restore points
of your app
when hosted in
a Premium App
Service plan.
You can even
download a zip
of the app.
Using the Data Migration
Tool with Cosmos DB
Learn more about Migrating data from one format to another is a common
Azure Cosmos DB task for application developers (even if it is just for testing).
here
I was recently building out an API and needed to dump
some data into Cosmos DB. The tool that made short work
of this was the Azure DocumentDB Data Migration Tool.
In my case, I needed to dump a large JSON file into Cos-
mos DB. Here is how I did it.
Get to work
www.dbooks.org
Open the Data Migration Tool and under Source
Information, point to the local JSON file as shown below.
You’ll need to append the Database name to the end of the string.
For example: Database=bible will be appended to the string
AccountEndpoint=https://mbcrump.documents.azure.com:443/;Account-
Key=VxDEcJblah==;Database=bible that I copied out of the portal.
Now press Verify Connection.
Give it a couple of minutes until you see that it has
completed pulling down your code from Git and then go
to the new URL of your site. You can find the URL on your
overview page. In my case it is, http://myquizapplication-
staging.azurewebsites.net/
www.dbooks.org
You can even click on View Command to see the command that
will be used to migrate your data. This is helpful to just learn
the syntax.
www.dbooks.org
Upload a File
www.dbooks.org
Working with AzCopy and Azure Storage
You can easily work with AzCopy to manipulate Azure Storage
What is AzCopy? containers and more. In this tip, we’ll explore AzCopy in the
AzCopy is a command line context of Azure Storage containers.
utility designed for copying
data to/from Microsoft
Azure Blob, File, and Table For this example, I’m going to use Windows. After
storage, using simple I downloaded and installed the utility, I navigated
commands designed for inside my command prompt to the following folder
optimal performance. %ProgramFiles(x86)%\Microsoft SDKs\Azure\AzCopy and ran
You can copy data between the azcopy.exe command to ensure everything was
a file system and a storage working properly.
account, or between
storage accounts.
(courtesy of docs)
Go ahead and open the Azure Portal and navigate to the Azure
Storage account that we worked with earlier.
Look under Settings, then Access Keys and copy the key1.
www.dbooks.org
Keep in mind: The main difference between these two commands is the use of SourceKey for
downloading and DestKey for uploading. The key that is being used is identical (named key1
from the example above).
We can do the reverse and upload a file from our hard disk to
Azure Storage Blob Container with the following command:
www.dbooks.org
Tracking Run Data with Azure
I’d like to share a practical example of how I am using Azure in my daily
life. I’ve started running outdoors and would like to extract several bits
of information that the app on my phone generates and sends via email
once the run is complete. Currently I open the email and save the
kml, gpx, csv files to my OneDrive for historical purposes. There is a
better way with Azure.
The pieces of data that we’d like to extract are the kml, gpx, csv URLs
and the last piece of the Explorer Link URL. After we have the URLs we
are going to download them automatically into a OneDrive folder.
● Filename - This is the general filename that the app uses, and I think
it’s a piece of data we want to store.
● CSV URL - A URL to the CSV File that we’ll be posting to OneDrive.
● GPX URL - A URL to the GPX File that we’ll be posting to OneDrive.
● KML URL - A URL to the KML File that we’ll be posting to OneDrive.
www.dbooks.org
Create JSON Schema to Be Used
in Azure Logic Apps
We need to create the JSON body which we’ll use to create the schema.
I used objgen.com/json to quickly create this piece, but you can just
manually type it if you want.
Here is the JSON payload with some sample data:
www.dbooks.org
Too easy! Now head over to the Zapier Editor and create a new app.
You’ll want to use the New Email Trigger and use the Email Parser by Zapier
and allow it to connect to your mailbox that you created earlier.
For the next step, you’ll want to use an Action that is a POST request that
uses Webhooks by Zapier. When you get to the point to where it asks you
for a URL, use requestb.in to see what your HTTP client is sending or to
inspect and debug webhook requests. Now you have a URL that you can
use for testing. Ensure your payload is set to JSON and now you can select
the data from your parsed email (filename, csv, kml, gpx). You can leave the
rest of the fields as they are. When you finish your screen should look
like the following:
www.dbooks.org
Go ahead and save and run the test. After you switch over to your
requestb.in you should see the output that matches the parsed data from
the email.
Note that the URL isn’t generated until we provide the parameters.
www.dbooks.org
Go ahead and press Edit. Remember the JSON Schema from the
last post? Well, now is the time to paste it in. I’ll also
include it below:
Note: You can use the “Use sample payload to generate schema” option,
but I prefer the additional meta data that JSON Schema can provide.
You’ll now have a GET URL that you can put in Zapier and replace
the requestb.in that we stubbed out earlier.
Head back over to Zapier Editor and modify your Zap by editing
the template and replacing the requestb.in URL with your live
Azure Logic Apps ones.
www.dbooks.org
Upload Files from a URL with
Azure Logic Apps
Open our existing Azure Logic App and we’ll use OneDrive to
automatically upload the files to my personal OneDrive account.
Typically, you’ll add an Action or Condition to trigger once the
HTTP request is complete.
Now you can pull the fields that we captured and use them as
dynamic content. For example, the GPX file contains the full URL,
so we can just use that dynamic field. For the destination URL,
we’ll construct the location we want it to go in our OneDrive
account. Note that I’ve also setup 2 additional OneDrive actions
for the KML and CSV file.
www.dbooks.org
Now you’d want to send an email to your Zapier mailbox to test all
the pieces to this app. Now you can switch over to your OneDrive
account. If everything goes well and worked successfully you will
see your new files in your OneDrive folder.
www.dbooks.org
It is fairly easy as all you need to do is open VS Code, click on
Extensions, search for azure function, and install it as
shown below :
Now you should create a project, then a function app, and select
which template that you want to use. After you select a template,
you’ll need to provide a name and an authorization level.
I typically fix this by going into the Azure Portal and clicking
on my Azure Function. I then click on Platform Features and
Advanced tools(Kudu).
www.dbooks.org
I then navigate to wwwroot and hit edit on the host.json file.
Inside the editor, add the routePrefix to define the route prefix.
So if I wanted the route prefix to be blank, then I’d use the
following:
Simply restart your Azure Function and now my URL is
accessible without api.
Keep in mind that best practice (as far as I can tell) is to use api, but wanted
to flag this as only you can make your design decisions.
www.dbooks.org
Productivity
If you jumped straight to this section, then you certainly understand
the spirit of what I originally wanted to achieve with Azure Tips and
Tricks - simply to be more productive with Azure. In this set of tips,
I’ve gone back to the first tip that I ever wrote describing how you
can use keyboard shortcuts within the Azure Portal to navigate more
effectively. We’ll also cover how you can apply tags to your Azure
resources to logically organize them by categories. We’ll wrap up
with using Azure Cloud Shell, which provides an interactive, browser-
accessible shell for managing Azure resources, and how you can
quickly take advantage of it with Visual Studio Code in the browser
or on your local development machine.
Actions
CTRL+/ Search blade menu items
ALT+SHIFT+Up Move favorites up
ALT+SHIFT+Down Move favorites down
G+/ Search resources (global)
G+N Create a new resource
G+B Open the ‘More services’ pane
Navigation
G+, Move focus to command bar
G+. Toggle focus between top bar and side bar
Go to
G+D Go to dashboard
G+A Move favorites up
G+R Move favorites down
G+number Search resources (global)
www.dbooks.org
Remember this!
Tags are user-defined Head over to the Azure Portal and select a service. In my
key/value pairs which example, I’m going to select a Web App that I want to tag as a
can be placed directly on Production App. Select the Tags menu and provide a Name and
a resource or a resource Value as shown below.
group.
If you pin the blade (by pressing the pin in step 4) you’ll see the
following on your Azure Portal dashboard:
www.dbooks.org
Add Azure Cloud Shell
to Visual Studio Code
www.dbooks.org
Very cool! If you want to see the source code for the app
it can be found here.
Did you know that you can access Visual Studio Code within a
Cloud Shell instance?
And since this is based upon the open-source Monaco project that
powers Visual Studio Code, you can expect we'll see more features
added over time. As of the publication time of this eBook, it
automatically includes authorization for pre-installed open source
tools like Terraform, Ansible, and InSpec. So what are you waiting
for? Go check out now!
www.dbooks.org
Conclusion
Thanks for reading and I hope that you enjoyed the top tips of
Azure Tips & Tricks since the creation of the series. While we’ve
discussed four broad sections that covered web, data, serverless
& productivity, there are 130+ additional tips waiting on you that
cover additional topics such as :
• App Services
• CLI
• Cloud Shell
• Cognitive Services
• Containers
• Cosmos DB
• Functions
• IoT
• Logic Apps
• Portal
• PowerShell
• Productivity
• Storage
• SQL and Search
Start free
signing off...
Azure Tips and Tricks
azuredev.tips
Copyright © 2018 by Microsoft Corporation. All rights reserved. No part of the contents of this book may be
reproduced or transmitted in any form or by any means without the written permission of the publisher.
www.dbooks.org