Okay.
Hello cloud gurus and welcome to this lecture and this lecture we're going to build our very first service
web page that uses API Gateway as well as lambda.
So let's have a look at what it's going to look like.
We've got our user and our user wants to go to Hello cloud gurus 2019 dot com but they don't know what
the IP address is.
So that's where Route 53 comes in.
And essentially our user sends a query across to Route 53 and it's going to respond with the bucket
address for our Web site and then basically our users then going to go over to our S3 bucket and they're
going to go to index dot HMO and when they view that page it will just show up as a static page so be
returned to their browser but there'll be a button there.
And when they push that button they're going to get dynamic content and essentially what's going to
happen is they're going to send a request through to API Gateway API Gateway is then going to proxy
that request to a lambda function the lambda function will then take the data and then return a result
to API Gateway which will then return a result to our user.
So it's lots of fun.
It's going to be very very hands on.
It is a lab and you will need to log into the adobe us console.
OK so here I am in the AWOL console I'm going to go over to services and I'm going to go to lambda and
this is the first time you've ever used lambda you'll get this splash screen.
So going to go ahead and hit create a function.
Notice there's three different things you can do here.
You can alter from scratch.
You can use blueprints or you can use the service application repository.
This is super cool because it's basically a whole bunch of applications that are available to you that
have already been developed and published on NWS.
This is super useful as well as the blueprints for creating Alexis skills.
You don't need to know how to program.
You can go in and create Alexis skills and then go through and edit them or have a look at how we do
that later on in the course.
So we want to go an author from scratch.
I'm going to call this my first lambda and then function in terms of the runtime environment we've got
a load of different runtime environments here.
So we've got dot net we've got go we've got Java we've got node J.S. we've got Python we've got Ruby
and we can even use custom runtime environments we want to go ahead and use python three point six and
in here it's RSS about a role so you can choose an existing role or you can create a new role from templates
if you've never used lambda before go ahead and create a new role from template I'm going to call this
my lambda execution and then roll and then essentially you've got a whole bunch of policy templates
in here so what is it you want lambda to be able to do and it is a little bit confusing and has lots
of different options but essentially what you want is the simple micros service permissions to go ahead
and click on that and then we're going to go ahead and click down here and hit create a function.
So that has now created our very first lambda function can take a little bit of time depending on your
internet speed and then we go it says congratulations your lambda function my first lambda function
has been successfully created now in here we've got our designer and we've got our function code and
then down here we've got our environment variables and a whole bunch of other different settings.
So let's just start with the designer in here we've got all the different triggers.
So what is going to trigger our lambda function now of course it is going to be API gateway but it's
really important going into your exam that you understand the different lambda triggers that can come
up in the exam note that RDX isn't here for example.
So it's actually more understanding what can't trigger lambda than what can trigger lambda before we
go ahead and configure this let's just scroll down in here we've got our code.
So this is our idea or integrated development environment and what I want you to do is I just want you
to go over to the resources section the course download the resources and then open up hello cloud gurus
dot p y.
Okay so I'm in my hello cloud gurus dot p y you will want to copy and paste this into your clipboard
you may just want to change the name.
So at the moment is my name.
Go ahead and put your name in there came back over.
I'm just going to go ahead and delete this and I'm going to paste this in here and go file save here
but also just understand that any changes that you make.
You also need to save up here.
So I'm going to go ahead and hit save.
So I've saved it both in my ADC as well as saving my function and in here all this does is basically
it's saying hey return a 200 response code with this particular header.
And then this body and the body is just Ryan Cronenberg.
So it's just returning my name.
So essentially if something invokes this code it's going to respond with my name.
That's all this function does it's super super super simple.
Down here we've got environment variables.
This is a way of passing variable information into your lambda functions so you can define static code.
I'm gonna use this in the next lecture.
Of course down here we've got our tags in here we've got our execution rolls.
This is our I am role in here we've got descriptions you might just want to call this my first lambda
then function in here we can allocate how much memory is delivered to this function we can also allocate
the timeouts you can have how many seconds before this lambda function times out when we go on and do
the poly we're going to actually increase this till about five minutes so that it has time to run the
function and in here we can choose what BPC we've got our debugging and error handling we've got concurrency
and then we've got auditing and compliance so we can start using cloud trail with it as well.
So we have gone in and we've edited our code and we've gone in and given our function a description
go ahead and hit save.
So your function is saved.
Next thing we need to do is configure a trigger system as we click on here.
It's going to get rid of our idea environment and it is going to configure our triggers.
So going to create a new API in terms of the security just click on AWB Yes I am.
And that's all we need to do.
And you don't need to change any other options just go ahead and hit add and that will now add our trigger
and then all you need to do is go ahead and hit save.
And now we have our API gateway as a trigger.
And essentially what this has done is it's gone in and created a new API endpoint and we can view this
in a couple of ways.
First of all you could just view this endpoint here by clicking here.
But you're gonna get an error message.
It's just saying missing authentication token.
So let's go back.
Just going back into my other tab and then what I want to do is I want to click on this link here.
My first lambda function API now will open up API Gateway and you can see in here API Gateway and I
actually really liked the UI for this because it explains what's going on.
So we've got a client here and they're sending a request and this request right now is any but we're
gonna change this to a get request.
This is then going to be a proxy to our lambda function which is here and then our lambda function is
going to respond and then it's going to proxy it back to our client.
Now right now we're allowing any function we don't want that so let's just go through and go to actions
and then we're going to delete this method and go ahead and hit delete that has now deleted it.
Next we want to go to actions and we want to create a method.
What method do we want.
Or we want to create a get request.
Go ahead and hit.
Yes.
And then in here what's the integration type where we want it to work with our lambda function.
And we're going to use lambda proxy integrations to click in here and here you've got your region.
If you just start typing in random you'll be able to find your function if you can't make sure you know
what region your function is in.
So here we go my first lambda function and then we're just gonna use the default timeout.
So once we've done that just go ahead and hit safe.
And it says you're about to give API Gateway permission to invoke your lambda function.
Go ahead and hit.
Okay.
And that should now go ahead and create it.
So now that we've created what we need to do is deploy our API.
So we need to go down here and just go to deploy in terms of our deployment stage just go ahead and
hit default.
And we could call it my prod deployment something like that deployment and go ahead and hit deploy.
And that has now deployed our API and we click in here we've got our stages.
If you go and click on get make sure you click on get here then click on this invoke you arrow and that
should open up a new tab.
Let's have a look.
Oh there we go it doesn't even open up a new tab opens up the same window and it's got my name.
So you should be able to see your name if you're not seeing it.
Make sure you clicked on the get.
So like I said before you've got to click on default.
Go all the way down to get and then click on this link.
So now that you've got that I want you to copy this link into your clipboard and I want you to open
up your index dot hate him mail directory file that we downloaded in the resources section get some
in my browser I'm just gonna go open with and then text wrangler I'm gonna go ahead and open this up.
So here's our code.
Essentially this code is running a script and it's doing a get request and we need to tell it where
to do the get requests so let's paste in our API Gateway link in here.
So there we go it's this you are old Dot API and then all the way through to my first lambda function
and then all this is doing is saying hello cloud gurus and that's got a little button called Click me
when you click this button It's going to run this function which is basically you're going to send a
get request to our API gateway.
So go ahead and hit save.
Now we're back in the AWB console.
We have got our API Gateway working its triggering our lambda function what we now need to do is go
ahead and configure S3.
So let's go over to S3 before you do this actually if you want to use your domain name just go down.
I don't know if you registered or not but you can go to Route 53 and you'll find your domain in here.
If you still got that domain name so I'm going to use Hello slugger is 2019 dot com.
Just double check that you have deleted your a record I hadn't a record in here still pointing to a
load balancer that idea hence gone on and deleted.
So let's go back over to S3 and I'm going to create a new bucket.
Just gonna type Hello cloud gurus 20 19 dot com now went all the way through this lab and accidentally
typed hell how gurus 2019 dot com and I got to the end with Route 53 and it didn't work.
So if you do see it in the video edits this should just be Hello rather than hell.
So I'm gonna go ahead and hit create.
Sir has now created our bucket.
Now the first thing that you'll notice about our bucket is that in here it says bucket and objects not
public.
Now of course we don't want this because this is going to host a Web site.
So let's go ahead and click in here and what we're gonna do is we're just gonna edit our public access
settings make sure these are all unchecked.
Go ahead and hit save and go ahead and just type confirm and that will then change our permissions so
that objects can now be public.
It's critical that you do that.
Let's click in here to go into our bucket.
We're gonna go over to our properties and we're going to configure static website hosting and then we're
just going to use this bucket to host a Web site.
We're going to use our index dot HMO HMO and then era dot HMO and we're gonna go ahead and hit save.
And so that has now turned on static web site hosting.
Let's go back over to our bucket and just click in here click the wrong button and then we're just going
to upload our files so go ahead add my files I'm going to add my error and my index dot HMO and go ahead
and hit upload.
And those two objects have now been written to S3.
And if I click in here and go to actions I'm gonna go ahead and hit make public.
I'm gonna go ahead and hit make public in that.
And you should see two success codes.
Now what we can do is we can click on our index in here click in here to go to your index start each
demo and it's loaded up this web page.
This is service comp in Austin at the time we didn't even have our Austin office open civil as comfort
brought us to Austin and we ended up opening a very big office out there.
So that's how main headquarters in the US.
And then all we need to do is click on this button that says Click me and there you go it says hello.
Ryan Kronenberg.
So that has just gone and queried API Gateway API gateways past that to Lambda Lambda sent a response
back to API Gateway which has sent a response back to our browser.
Now if you really want to complete the rest of this lab what you can do is if we just go back over to
AWB s just maximize the screen then go to our services and we can hook up Route 53 to our S3 bucket
seem to go in here go to hosted zones.
Hello club gurus 2019 dot com and we're gonna go in and create a record set.
If you haven't a record in here make sure you go through and delete that records set.
Gonna go ahead and hit alias in here.
I'm gonna click in here and we can see Hello cloud gurus 2019 dot com.
So it's got exactly the same bucket name as my route 53 domain name.
So go ahead and click on that and go ahead and hit create.
So that will now create a record set for Hello Calgary is 2019 dot com.
DNS can take some time to propagate but let's give this a shot now so.
Hello cloud gurus 2019 dot com.
And it's not working.
And just remember the haiku from the start of the course.
It's not DNS.
It can't be DNS.
It was DNS.
Supposed it for about five minutes.
Let's go ahead and hit refresh.
And there we go it was DNS.
So here it says hello cloud gurus.
Let's go ahead and click me.
And there we go.
It is now talking to API Gateway which is talking to Lambda which is passing response back to API Gateway
which was passing a response back to my browser.
So that is a super simple very quick service website.
In the next lecture what we're going to do is we're going to add some complications to it.
We're going to go out and create a service web site using the poly service and you'll be able to upload
your notes that you've been taking throughout this course and you'll be able to put them into this Service
Web site and it will spit out MP 3 files so you'll be able to get your notes read back to you.
And then what we're going to do after that is we're going to hook this up to an Alexa skill and you'll
be able to get Alexa to help you study and then you finished the course.
So that is it for this lecture everyone.
If you've got the time please join me in the next lecture.
Thank you.