A Lap Around Microsoft Azure by Joseph Guadagno || Azure Virtual Conference
10K views
Nov 16, 2023
Conference Website: https://www.2020twenty.net/azure C# Corner - Global Community for Software and Data Developers https://www.c-sharpcorner.com
View Video Transcript
0:00
So, my name is Joe Guadagno
0:05
Most people call me Joe G because my last name is kind of hard to pronounce
0:09
As Mahesh and Magnus mentioned, I am a director of technology at Quicken Loans
0:16
We're going to kind of walk through, if you want to follow me on Facebook, Twitter, or anything
0:20
here's all the contact information. I'm also on Twitch at Jake Wadagno, where I stream three times a week, Monday, Tuesday, and Wednesday at 7 p.m. Pacific time, covering all kinds of topics
0:36
You can find out more on my GitHub repo at github.com slash Jake Wadagno or my website
0:43
So we're here to talk about Azure. So as I started to rearrange this talk, I gave it a couple of years ago, and a lot has changed since then
0:55
I started thinking about talking about all of the different resources that there are in Azure
1:02
and then realized there are way too many resources available in Azure
1:07
especially for a 45-minute talk that will most likely be cut down to 30 minutes because I'm at the end of the day
1:14
and conferences tend to not run on time. So I tweaked the talk a little bit
1:20
We're going to kind of cover, take a basic .NET application, which has an API and an MVC portion to it
1:31
Then we're going to publish that to the cloud. And we'll cover Azure Web Services
1:38
Azure App Service, Azure SQL. and if we have time at the end, Azure Blob Search
1:46
And just to show you how easy it is to get in, I know you see a lot of talks
1:51
and especially if you're watching anyone from Microsoft or Amazon, it's always those quick hello world apps
1:59
They right-click and three seconds later, you have 700 deployed VMs. I'm going to take you a little step back
2:05
and give you something hopefully a little bit more realistic. So as I said, this is a lap around Azure
2:13
It's really a partial lap. We're not doing a full marathon. We're not going to run 26 miles
2:18
Luckily, we're not going to run at all unless you're on a treadmill while you're watching this
2:22
We're just going to exercise your mind with this. So we're going to start off with creating two app services
2:30
So we're going to be able to publish a web app and then publish an API to it
2:36
After we do that, we're going to publish a SQL database with it
2:43
This application requires a SQL backend. It doesn't have to be SQL Server
2:48
It could be SQLite. It could be anything, but we're going to publish it to SQL. Then if time allows, we're going to use something called storage accounts
2:56
that the application we're working on is a context application to manage, you know, first name, last name, date of birth, that kind of stuff for context
3:06
But it also has an image component to it. If time allows, we will publish those images to blob storage
3:14
And then if we're lucky, we'll start working on a content delivery network to be able to expose that and then run into applications insights
3:26
So enough about that. We're not at the finish line yet. We're just at the getting started
3:31
So let's take a look at this app and what we are going to do. So this is a pretty basic application
3:39
If I hit run, you'll notice I'm using JetBrains Writer and not Visual Studio. There is really no particular reason for it outside of I really like Writer now compared to Visual Studio
3:52
but I didn't say that live, but the world is watching. It just has a couple of benefits to it
4:00
I'd started my stream using my Mac, and the writer really does have a cross-platform way of doing it
4:09
So here's our API endpoint. We have a context endpoint that just spit out a bunch of JSON
4:16
and then there's a viewer to it. Nothing major, a typical MVC app
4:22
We're just going to show you the power of Azure to be able to deploy this in hopefully under 27 minutes
4:32
That's assuming also I don't make any mistakes along the way. So let's start off here
4:39
So the first step is I'm logged into the Azure portal. I did that ahead of time just to avoid any of the two-factor authentication that I have set up for it
4:48
So first thing I like to do whenever I'm creating an app, especially one for a presentation, is start off with creating a resource group
4:59
A resource group you can think of as a logical binding for your applications
5:04
It's a way to kind of group them together. Allows you to look at billing firm
5:09
Also allows you to both delete them. So when this session is done, I can just come across and delete this
5:16
So I am going to call this a lap around Azure. And because I am in the U.S. in the western part of the country, I am going to choose West U.S. to be a little bit faster
5:33
For me, click create. And within seconds, that resource group is created
5:40
I can click on go to group and you'll see nothing here. So the first thing we want to do is to add what's called an app service plan
5:50
So an app service plan allows us to host applications. Think of it as like a virtual IIS box or a virtual Windows or Linux server that allows you to host more than one app
6:07
So we're going to create one that allows us to host our two applications
6:11
So when I click create, see it automatically talks about my subscription and puts in the resource group since I created it from there
6:23
Then we're going to give it a name. Let's call this. These names have to be unique, so sometimes you have to get a little creative
6:33
So I'm going to do LAA, follow up around Azure, and then API-app
6:39
So names don't necessarily mean anything. It's just more for logical how you figure it out
6:47
And I'm going to choose Windows for this just in case some of the libraries you might use might be Windows specific
6:54
In our case, it's not, but I'm more comfortable with Windows than Linux. So I just chose that
6:59
And then again, the region. And you want to try to keep the regions in the same thing so you don't run into costs when it comes from going from one environment to the next
7:10
And then the type of server. So there's lots of different options and the cost varies tremendously on it
7:19
Luckily Azure gives you kind of a little sample of roughly how much it would cost The cheapest production box costs about US a month and can go up as high as thousands When you just developing and testing I recommend you go
7:40
with either the F1, D1, or B1. I'm not going to do that for this because when I was running through
7:47
these demos last night, these are usually shared resources and they're not guaranteed to be up
7:53
And while I'm doing a demo, I want to make sure they're up. So I choose one of the production mindsets
7:59
And we're going to go with the cheaper S1 for now, which has more than enough power to run that simple app
8:09
Click review and create. Hopefully, you get the green checkmark that everything's there
8:13
I click create. In a couple of seconds, that will be done
8:19
done. Once it's done, we'll go to the resource and start with our next one. Okay, it's done
8:28
I'm going to click go to resource. And then you'll see this section here called apps. And there are
8:36
no apps to it. So you're good to go. Let's create the next app or the first app, which is going to
8:43
as you could imagine, we are going to create what's called a web app
8:50
Whether it's an API or an application, this is essentially running Kestrel or IIS for you
8:58
We're going to click create, choose that resource group, give it a name
9:05
I am going to do la-webapp. Let's do the API first. API-app, and I'm going to do it through code
9:20
I can publish a Docker container, but that's a little bit beyond what we're going to do
9:25
And this particular app is written with .NET Core 3.1, so I'm going to choose that
9:30
Windows, and let's go back. For some reason, it always defaults to central
9:36
so let's do west, and I'll go down to west2. Now, it's going to look within West 2 to see if there's any existing app service I have
9:46
And I should have three in there. Context Web, which is what I've been using for my stream
9:53
LA-API app, which is the one we just created. And LAT app service, which is what I created last night to make sure the demo worked
10:03
And in the event that we ran out of time or there was failures, I have a fallback
10:09
So let's go and create that. And this takes a couple of seconds once the validation passes
10:17
While that's happening, we're going to go and create the next one
10:22
And a lot of these you can actually create through Visual Studio, Visual Studio Code, or JetBrainsRider
10:30
I'm just creating it here to show how you can do it in the portal
10:34
But you can also, as Mustafa mentioned, you know, the real way you want to create infrastructure is through scripts using something like Terraform or the Azure Resource Manager
10:45
So it's repeatable and you don't make mistakes. But I like to learn from the, I like to learn from scratch
10:54
So this is the way I'm showing everyone else how to do it
10:58
LA-web-app, Docker, still the same 3.1. Too bad there isn't a way to just go and copy
11:09
I want an exact copy of this. Just change the name. And then it's going under the LA app
11:16
Click review and create. Click create. So once this is done, it's been eight minutes now
11:25
I've created an app server and I've created or in the process of creating two web applications to go there
11:34
So we're almost there. Next thing we want to do is create a SQL server instance
11:42
So I'm going to do new again and then search for Azure SQL
11:50
You can actually search for SQL. Click create. Now, this one's the creation experience is a little bit different
11:57
It really just depends on your experience. But for this one, there's three different offerings that you have for SQL Server
12:10
There's SQL databases where I just want to create a database. I want to create a managed instance, meaning Microsoft slash Azure
12:18
You're going to manage everything about this. This is typical when you want to grab an existing on-prem database and just say, here, Microsoft, you manage it
12:28
And then the SQL virtual machines is you really control everything about it
12:33
You get a machine that has SQL server preloaded. You're responsible for the operating system updates, any updates to SQL server
12:43
Easy demo, easy app. I'm going to go with SQL databases. First, we want to create a database server because we need the database server to host the database
12:54
And it defaulted to Presentations India because the last talk I was giving was supposed to be at C Sharp Corner in India
13:01
And that's why that resource group is selected. So let's go, what do I call it
13:08
A lap around Azure. And we are going to give it a database name
13:13
Let's call it LA SQL. server. You notice I use law because when you're looking at the resources, it kind of sorts them
13:24
for you by application. You can also do that by resource group, but this for me
13:29
does a little bit better. Now, you need to create an equivalent server administrator. And if you
13:36
notice in the text, it says that this needs to be something other than a typical name. You can't
13:46
use admin, administrators, SA, root, or anything that's commonly there. What they're trying to do is reduce the vector for your attacking
13:56
So I'm going to use jguedagno. And then for a password, type in something that you're going to remember
14:03
I use something like LastPass for my password so I can generate it
14:08
Since this is a demo here, I am going to use the typical demo password of password1
14:16
And it doesn't matter that you know because I am going to destroy these instances right after the talk is done
14:25
So I'm going to do review and create. This one takes a little bit longer to do because it has to create a new virtual machine or find one that's available, throw it on there, and get it ready for you
14:46
So while that is happening oh there it is It done That was quick Oh no it was just accepted So we are going to get ready to next step is install the database to it So we got the actual server We going to want to put our context database out here
15:07
Luckily, I have scripts for all that. So you're just going to see me copy and paste when we're ready
15:13
And this is just a lot of filler talk right now while this creates
15:18
I've thought about actually creating the database behind the scenes and just having it ready
15:22
but I thought it was important to see it. And I was able to pass the time enough to do it
15:30
So now I'm here. I can see everything there is about the database. I'm going to choose Create Database
15:37
And then it already has the subscription and resource selected, looking for a database name
15:43
So I am going to call it Context. Then you need to choose the database like we did with the app server
15:52
and the server itself, what kind of throughput do you want? The default is this general purpose one, which is a whopping $380 to run
16:04
If you go to like the most business critical, you're talking thousands of dollars an hour to run these
16:11
For our example, we are going to use just the basic and start off with the minimum of 100 megs because there's really nothing there
16:20
And that puts us around. $5. I click apply, review and create, create, and this should only take a couple of seconds
16:34
a minute at tops to create. Once it creates, we'll go to the resource page to get the basic
16:42
connection info for it. Now it should be something like la-sql-server.azurewebsites
17:03
or databases.azurewebsites. I forget the full syntax, but we'll see it here
17:08
once this deployment step is done. And then we will jump over to Rider and do our database connections to get ready for the actual connection
17:25
So come on, come on, come on, Azure. It's always awkward when it's trying to run and you're in there
17:37
Let's see. Oh, my green screen cut out. Okay, now it's done
17:47
So let's go back to the code. Let's copy this out because we need the server name
17:56
So I'm going to hit copy. Go to Rider, and Rider has a built-in database explorer
18:02
So let's go and create a new one. You can also do it from their Azure Explorer
18:08
like you would do in SQL Server. Click on the SQL databases
18:15
Give it a second to refresh. And it should appear with seven or eight different databases, five of them
18:26
So this is the one we recently created, and I want to connect to the contacts
18:31
So I'm going to right-click and choose Connect to Database and try to log in
18:39
And the reason why I said try to log in is because the login is going to be unsuccessful
18:45
There's a reason for that. So as soon as I hit connect, I should try in a couple seconds
18:50
and then I'll get this message here that says this is specific database user password combination
18:57
is rejected by the server, cannot open server, client with IP address is not
19:05
and then blah, blah, blah, essentially saying that, I did not allow, excuse me, or authorize this database to connect, which is true
19:20
Azure has a built-in firewall to SQL databases that only allow specific connections
19:27
So we are going to create a server firewall rule. If you notice within Azure or within Rider, if you were watching, where did it go
19:37
So when I right-clicked here, there was a set firewall rule, which allows you to do that
19:45
But I'm going to do it here only because there's another change we need to make. So set firewall rule
19:51
And then there's a simple add client IP right here that you'll click
19:58
But you'll notice below it adds in a client IP address, which is my public IP
20:08
And what I typically do is just put in a name for it here, like home connection, just so I know in case there's other
20:23
Now, later on, we're going to want to expose this application or this database to other Azure services
20:33
So we're going to want to check this box here or say allow Azure resources and services to access this server
20:42
So I'm going to click yes to those and that just saves us a step later on
20:46
so now that that is done let's go back to our application
20:55
and choose okay to see if it works now i probably have to retype the password
21:03
did i get the password wrong I did this the other day
21:14
I got the password wrong multiple times. And it looks like I got it wrong again
21:22
If I get it wrong, I'll just show you how to reset it
21:32
Test connection. Yep, I got it wrong. Oh, it still says the firewall was not there
21:38
The change probably didn't happen yet. Save. There it goes. Usually it doesn't take that long to actually save
21:49
So now let me go back. It wasn't me mistyping the password
21:53
It was just Azure. It was not ready for me. I click OK
21:59
Test passed successfully. I click OK. And I am ready to access database
22:08
There is nothing there. So I am going to run a couple of scripts just to get our database there
22:15
So let's open a query console. You can do this in SQL Server Manager, Azure Data Studio, Visual Studio Code, whatever your poison is
22:24
You can even actually do this online in Azure So I am going to run a quick test And my eyes are looking at a different screen
22:35
because I am copying some text. So this is everything we need to do to create the schema
22:45
I could have done a backup and a restore, but that's pretty complicated
22:49
I want to make this sample something that everyone could follow. So you can recreate this database and everything as needed
22:59
So in a couple of seconds, we're done. Now I want to create the user
23:06
So for that, there's two steps for creating the user. So let's get rid of all this text
23:14
It's the user. This needs to be done in master. Don't worry about password
23:19
Like I said, I'm deleting this database and everything else after this talk
23:25
Click run. That's done. Now I want to create a local user and give it the rights
23:33
The reason why these are done in multiple scripts is because the Azure client doesn't support
23:40
the Azure database doesn't support you being able to change databases on the same connection
23:49
So what's happening behind the scenes is writer in this particular case is creating a new connection because I am changing the database that I'm going to, as you kind of noticed here
24:02
So I can't do any use statements inside of the IDE. And I do this
24:11
Our user's created. It's got DB reader and write access. I do this so that it doesn't have the super SA user to it
24:20
Now the last step is for me to populate it with some data
24:25
And I'm only populating two of the tables with it. If I can only copy the text
24:35
you'll see we're populating the context table and the phone table. Control A to run them all
24:45
Run it. So now it's done. So now I have the database up there. Database is populated. I should be able to come here and do jump to query and let's do a new one and do select star from contacts
25:07
and should see I have four or five contacts in there. So database is good, and this is going out to the cloud
25:17
So now that we are done with that, the next step for us is to publish the API
25:26
Now, publishing the API, there's four or five or six or seven different thousand ways of doing it
25:33
I like to try to stay within my environment. So here I'm staying within Rider, just like you can stay within Visual Studio Code or Visual Studio proper and do it
25:48
There is an ability for me to right click and choose publish, which is what I'm going to do now
25:54
And then there is a publish to Azure, which I am going to pick
26:01
and then it wants to know if I'm going to use an existing app or create a new web app
26:06
So this is where I could have actually created those web apps ahead of time
26:12
or not created them, but actually created them physically from here. So if I expand this dialog box a little bit, you'll see all the different applications
26:22
And I should see LA API app right there. and I am going to open it in a browser after publish and click run
26:34
And then you'll notice down here, it's starting to build it. Now it's building a zip using the Azure resource API
26:45
It's going to upload that zip and then it'll give me a URL that I could get to
26:51
to validate it works. so I think I clicked open it up but if not let's go and open it up and if I configured it correctly
27:04
it should fail and it does fail and it fails for a reason problem is there's no settings to it so
27:12
it doesn't know what to connect to the database because I have our I have all the app settings
27:19
as blank in production because I want us to create them on the server
27:27
and I don't want them checked into source at all. So this is just the shell for Visual Studio or .NET Core to be able to access them
27:38
So we're going to go and do all the settings afterwards. Let's go and migrate the web app and then do the same step for that
27:48
Do publish, publish to Azure, search for that web branch, which should be the next one down from here
28:00
And then do run. This time I'm not going to select open in browser because we know it's going to fail
28:10
So while that's happening, let's go back to the portal. and take a quick look at some of the settings that we need to change
28:24
Here's the portal. So we're going to go to home and then look for La app
28:31
which is not in my most recent, which is weird because it was most recent
28:35
but I don't understand the real how that works. But if I click on apps here, I should be able to get to it pretty easy
28:44
And then the configuration is here. And you'll notice you get like a grid-like look to create
28:52
And pardon me, to save some time, I am going to copy and paste some of that data
29:02
So the only one we really need for this is a new connection string that we will call contacts database SQL server
29:13
And then if I have everything else correct, I'm going to paste this string, but the password is different in this one
29:25
I didn't put it in the zero. And then choose SQL server
29:32
I'll show you where to get this. It's pretty easy to get that connection string
29:38
Azure actually provides it. So if I do open a new tab
29:42
just so we don't lose our place there, and go through some of the connections
29:49
I can click there for contacts. There is a show connection strings right here
29:55
where I can click copy and it'll copy the ADN Go.net or the ASP way of connecting
30:05
But I had it on the clipboard because we've already used it before
30:09
I think that's all the connections we need for this. So let's click save
30:15
Click continue. As a result of the save, it's going to restart the database
30:22
Or sorry, restart the API app. Once that's done, I can come back to this page where we tried to view it
30:30
And then do contacts because that's the endpoint name. Try it. And if I got everything correct in the first shot, which would be a first
30:41
we should have access to it. And it says this page can't currently handle the request, and I get a 500 error
30:50
So let's see if it actually already refreshed. Let's make sure our database string is correct
30:56
Oh, it did not work. because actually no, the API should have worked. So let's take a quick look. While you're testing
31:07
it's easy to do something like this. So I am changing my environment to say development. This
31:15
will give me that old typical yellow screen of death that used to get with ASP.net core or ASP.net
31:22
but they didn't like the color yellow. So they went away from that. So I'm going to click save
31:28
continue. Now I'm pretending it's a development environment, which kids don't try this at home
31:34
You shouldn't do when you are working in a real app. We're just doing this to kind of show you a
31:40
debugging way of testing when you're not in prod and to figure out what I missed
31:51
Takes a second because it's got to re-spin up the service. and the login failed for contact users
31:59
I must have the password wrong. Let's see what I did for the password
32:07
Oh, I created a user with a password. So I did have the right password
32:13
I changed it in the connection string, which I shouldn't have. My apologies
32:18
So let's go back to our Azure portal. Change this. I thought I actually changed this code, but we didn't
32:31
So I'm going to click edit. And this password really is password Now there other ways of doing it You can use managed identity but I didn want to throw too many new things at you all at once So let hit save continue While that goes
32:54
I'm going to do a quick peek over to see if they want me to wrap up since we're getting into
32:59
the time that my talk was supposed to be done. And so far, no comments from them
33:10
So let's go back here, do a refresh. And if everything is fine, I should be able to connect
33:19
And there, now I have my API. So let's get the database working
33:23
We got the database working. Let's get the API up for the web app
33:29
up and it should need like two more minutes to do this and then we're going to have to create a blob
33:36
container for this to work so let's go to publish we actually already published it we need to do the
33:43
permissions for it where are you that one let's go to home choose our app service plan since the web is not there
33:59
choose web. This one needs a couple of more points. So I need to create a setting called
34:11
API root. So let's go to configuration. There is a way you can do this through the ID. It's just
34:20
a little bit hard to do in Rider. In Visual Studio, you can right-click and upload them all
34:33
which is a nice little feature. But again, your users should not really know
34:40
so these connections should be in Azure App Configuration. I think it's called Azure Configuration Service now, or in Key Vault
34:54
But since this is a demo, we break all the rules in a demo
34:58
We're going to leave this blank for now because we don't have the storage account created
35:03
Then we need to create the container name setting. And then this is going to be contact-images
35:15
As you can see I done this demo once or twice We have different IntelliSense coming up And then the last one is image URI
35:29
And this wants the fully connected string. So I am hoping this is available so I don't have to come back and type it
35:44
I hit save. I still can't run it because this app is dependent on having the blob storage
35:52
So let's go and create a blob storage really quick. So I'm going to do new storage, storage account, create
36:03
And then you get a lot of the same stuff. And let's do what I call it, lost storage
36:10
It's now fancy, or it's French. and then we're going to choose standard storage
36:16
The only thing we're going to change is this read access. All these options, like everything else, have a cost incurred to it
36:23
This is the cheapest and most cost-effective option. You have an option of cold or hot
36:29
If you're planning any real-time access to data, you want hot. Cold is for things like archives, backups
36:35
and things you don't need like instantaneous response for. So I'm going to click review and create validation passes
36:44
So now I just create it. Man, I feel like I'm talking a thousand miles a minute
36:51
Once this is done, we're going to create the container and then create the blob
36:57
Then I'm going to copy out the access tokens to it and provide that to the application
37:08
then we should be good to go so we're good here let's go to containers and then create a container
37:18
and then we call this container i think it was contact images
37:24
contact image oh we got to do it here contact dash images and public access level for now
37:39
because we want to access this directly from the browser we're going to choose blob anonymous read
37:45
only typically you'd want private and then set up the azure identity to have access to it but
37:53
because we are running out of time and that's a little bit more complicated
37:57
We're just going to create that. Now in order to get that we need to have an access key So I am going to copy this An access key is kind of like the credentials If you think in the OAuth way this says I authorize this user
38:15
Don't try this at home. Don't ever give out both your keys. You only get two keys. If one gets
38:21
stolen, you have to kind of regenerate them. But like I said, everything from this resource is going
38:27
to be disabled once I do it, so I don't mind that everyone sees it right now. Now I'm going to go
38:33
and edit this based in the code. Click OK. Click Save. Now if I configured everything right
38:48
if I go to the viewer app, which should be this web app, I'm going to go to the overview
38:57
and click on the API, fingers crossed. It loads, it loads. I click containers or I click contacts
39:09
That goes out to the database. Right now, this is calling the API, which is calling the service and did it
39:15
Let's go and edit a picture. I should get a contact here
39:19
As you see, last time I tested this was local host. So let's go and browse and upload
39:26
and let's pick Monopoly, Joe. My team loves to Photoshop my face into different pictures
39:35
I click Upload, and there is Monopoly Man that is now in the container
39:42
And where are we? If we go to More Tools, Developer Tools
39:48
if I inspect this element, you should see here that it is coming
39:55
from lawstorage.blob.core.azure.net slash contact images. So it saved it, uploaded it, pulled it into its own container
40:10
and it is good to go. Steve and I are ready to be joined back into the talk
40:17
I will be bringing all of this back to on GitHub over the weekend
40:27
So you will have access to the code and the scripts to try this out for yourself
40:47
Thank you
#Cloud Storage
#Distributed & Cloud Computing
#Enterprise Technology
#Software
#Web Services
#Windows & .NET