Okay.
Hello loggers and welcome to this lecture and this lecture.
We're going to look at lambda and this is the serval section of the course.
This is the very last hands on section and in this section we're going to just learn the theory of lambda.
Then we're going to go ahead and create a service web site using API Gateway as well as lambda and then
in the next lecture we're gonna go on and we're going to create a skill we're going to create an extra
skill and most people don't realize this but every time you talk to elect so you are talking to Lambda
you are talking to the cloud.
And when Alexa responds back to you that is the cloud talking back to you.
So before we go on to what lambda is let's talk a bit about the brief history of cloud.
So we used to always have data centers and essentially basically all organizations would have their
own data centers.
Some would use you know providers like Rackspace for example and would all be physical hardware.
So when you ordered a server there would like a web server let's say that would actually be a physical
server dedicated to you.
And you know I used to work in the cloud when this was the case and sometimes it take 10 days to provision
a physical server.
Some companies I work for it takes six months.
So when you went in and you ordered it and say you wanted to web servers to database servers a load
balancer some firewalls and then some San that could take anywhere from 10 days to six months to provision
and then Amazon came in and launched E.C. two in 2006 and suddenly you could provision virtual machines
just using a simple API call you could have a machine with you ready in minutes and it completely changed
the entire architecture completely changed the entire game and public cloud started becoming bigger
and bigger Rackspace and Amazon went to war with each other.
But Amazon could basically completely outspend Rackspace you know on investment and then I basically
moved around the U.K. cloud industry so I left Rackspace and went to work for a whole bunch of other
cloud providers.
And it's when I actually saw cloud formation that I started realizing how powerful W.S. cloud was and
how infrastructure was being turned into code so basically E2 was launched in 2006 that was infrastructure
as a service.
We then moved on to platform as a service.
This was Microsoft a really big in this space.
And then Amazon launched things like elastic beanstalk for example it's a good platform as a service
example.
So this is where you upload your code and essentially what will happen is the public cloud provider
will provision all the infrastructure underneath.
You don't need to worry about that then containers started really taking off in about 2014.
So Docker for example we didn't really cover containers in this course they didn't really come up in
the solutions architect exam.
They do come up in the developer and CIS ops administrator associate exam and then basically containers
moved on even further and we went to service and with server literally all you worry about is your code
you put your code up into a W.S. or into the cloud and then someone will go and do something.
So it might be uploading a file to S3 or it might be just a request from API API gateway but something
will go in and trigger that code and you're only paying for the execution times you're only paying for
when that code is being executed.
And that's really the full evolution of cloud we've gone from physical servers inside data centers are
up to almost the ultimate apps abstraction layer now which is just focusing on your code and not having
to worry about anything else underneath it the containers you still have to worry about managing the
containers and then you get like things like Cuban eddies for example that do that at scale but with
service you don't need to worry about managing anything all you need to worry about is your code.
So that brings us on to lambda and what is lambda well lambda is the ultimate extraction layer.
So you've got your data centers inside your data centers you've got your hardware inside your hardware
you've got your assembly code and protocols you've then got your high level languages you then got your
operating systems that you're running you then got your application layers as well as AWOL says APIs
and on sitting on top of all of that or extract it extracted away is AWOL lambda.
So basically eight of us handle all of these things for you all you need to worry about is your code
so don't use lambda is a compute service where you can upload your code and create lambda functions
and AWOL lambda takes care of provisioning and managing the servers that you use to run the code you
don't have to worry about operating systems patching scaling et cetera et cetera all you do is worry
about your code and you could use lambda in the following ways you can use it as an event driven compute
service where AWOL lambda runs your code in response to events and these events could be changes to
data in an Amazon S three bucket or a dynamo db table etc. and there is event driven compute services
are called triggers and then you can also use it as computer service to run your code in response to
heat TTP requests using Amazon's API gateway or API calls made using the AWB SS decays.
And this is what we use it for.
At a cloud guru we actually use it in both of those ways.
Actually when you upload a video to our site using S3 that will then trigger an elastic trans coda job
and so we use it both as an event driven compute service as well as a compute service that runs in response
to hasty V.P. requests that are hitting API Gateway and we'll cover that off in a couple of slides so
it is lambda.
Well let's say we've got our user here's our user and they want to create a mean.
So they then upload this meme to an S3 bucket and that triggers a lambda function and the lambda function
essentially will take that meme and it will basically take the metadata as well and it will put the
words Why for example over the meme.
So that was b how it creates a meme and the cool thing about lambda is it can trigger other lambda functions
so it can trigger another lambda function to tell the user that here.
Here you go here's your name and it could also trigger another lambda function to store that meme back
in an S3 bucket and then you could use cross region replication to store that mean somewhere else in
the world the other way lambda works is as a compute function.
So we've got our user they sent a hate P request to API Gateway API Gateway then proxies that to Lambda
Lambda will run the code in response to that each TTP request and then send it back to API Gateway it
will send it back to our user and the cool thing about the way lambda scales is let's say we've got
two users with two separate each TTP requests both will hit API Gateway and both will trigger to the
same lambda function that it will be separately run so that we separately are isolated from each other.
And of course they return a response back to the user.
So lambda is a bit different in orders from auto scaling in that you know obviously when to use it goes
in you might just spread it across to web servers.
If you have a million users hitting your API gateway at once that will then go on and trigger a million
different lambda functions.
So that's how well it scales.
We really need to talk about traditional architecture vs. service architecture because this comes up
an awful lot in the certified Solutions Architect associate exam.
So traditional architecture in cloud has always been you user sends a request it hits route 53 let's
say and then goes onto your elastic load balancer you load balancer sends it onto your Web servers and
then your web servers might communicate with a backend RDX or database server and then it sends back
a response to the user.
Now that's all well and good but you're still relying on physical Well you still relying on virtual
machines you still relying on operating systems.
Now the cool thing about the service architecture world is that basically you send a response to API
gateway that then sends a response to lambda and that can write to dynamo DP or it could write to Amazon's
Aurora or server lists Aurora and then send the response back to the user.
But like I said if you get a million users hitting API gateway at once and assuming you haven't throttled
API gateway that could it will scale to that instantly.
You don't need to worry about auto scaling or your you know your easy two instances becoming overwhelmed.
So service architecture is a much better way of architecting your products and in the exam you're gonna
be asked to create a scenario where you have all these different scenario questions and essentially
what they're testing you on is how well do you understand service architecture.
Just remember that you're always going to have API gateway at the front end to serve the request you're
gonna have your lambda functions that scale out automatically and then you're going to have a basically
a if you're going to go service you want a database that server.
So either be a dynamo DP or it could be a raw service as well.
So what languages does lambda support.
Well it supports no J.S. Java Python C sharp supports go and it also supports power show.
And in terms of the how lambda is priced it's priced on two different things so it's priced on the number
of requests.
So the first one million requests are free and then you only are paying 20 cents per 1000000 requests
thereafter.
We at a cloud guru I think we grew to like 300000 students before we even started getting a lambda Bill.
So it is amazingly cheap.
It really allows startups to scale very very quickly.
Even now we're getting close to a million users and our lambda compute Bill I think per months about
400 dollars.
We were actually doing the same level of compute across E2 we'd probably be spending upwards of one
hundred thousand dollars per month.
So that's how much lambda has saved our company and that's why you should really look at going services
then you also build on duration so however long your function is runs will basically Bill.
So let's say your function runs for 100 milliseconds then you're going to be charged a certain amount.
If it goes for 200 milliseconds or a minute or 10 minutes then you're gonna be charged more and more
so you're charged on the number of requests and then the duration of the requests.
So why is lambda cool.
Well you don't have to worry about any servers.
You don't need system administrators anymore you don't need to worry about patching your operating system
you don't need to worry about antivirus you don't need to worry about why you're easy to instance keeps
crashing.
You don't have to worry about servers at all.
It continuously scales.
Like I said every time you make an invocation to API gateway that will trigger a separate lambda function
and it's super super cheap.
Like I said you know we spend 400 bucks a month on now compute.
Bill when really it should probably be in the regions of 100000 or so.
So lambda is seriously cool and like I said every time you deal with Alexa so every time you speak to
an Amazon Echo or to a echo show or an echo dot or whatever you are actually directly speaking to Lambda.
So it is really cool when you think about it you are speaking directly to the aid of U.S. cloud and
the AWB cloud is speaking back to you.
So onto my exam tips.
Just remember that lambda scales out not up automatically so if you have five invocations that's going
to scale it's gonna scale out to five different lambda functions being executed at the same time.
Remember that lambda functions are independent.
So one event equals one function.
Remember that lambda is serving this and you should really go into your exam.
Understanding what services are serving is so arduous is not service it's even though you don't have
to worry worry about the operating system.
Amazon takes care of it.
There is still an operating system there that they have to go in and patch and you still have downtime
whenever they're doing maintenance and stuff.
The exception to that obviously is raw surplus.
That's the only RDA service that is surplus.
Things like dynamo DP things like S3 things like lambda API gateway or service technologies easy to
obviously is not is is not surplus it's a virtual machine and then just remember that lambda functions
can trigger other lambda functions so one event can actually equal X number of functions if functions
are triggering other functions.
So you could have one event which triggers off 5 or 10 or 15 or 20 different lambda functions and then
just remember that architectures can start getting extremely complicated with the lambda and it can
be really difficult to debug these and that's what the AWOL x ray service allows you to do.
It allows you to go in and debug what is happening with the Lambda.
We're not going to have a lecture on x ray because literally all you need to know is what it is.
So it helps you debug your service.
You know your service applications and then lambda can also do things globally so you can use it to
back off an S three buckets to another S3 bucket etc etc and go in knowing your triggers and we're gonna
cover this off when we go in and build our service website when we go in and build our Alexis skills.
But you really need to know the different lambda triggers you'd need to commit them to memory or at
least you should know what can't trigger lambda.
For example RDX cannot trigger lambda as of yet so that is it for this lecture everyone.
If you've got any questions please let me know.
If not feel free to move on to the next lecture where we're going to go in and create our first surplus
website using API Gateway and Lambda.