- Here we'll run through a demo
of just a simple Hello World application in AWS Lambda.
We're logged into the AWS console.
I have gone from here, I have gone to compute,
AWS Lambda, and we find ourselves here
at the Lambda initial screen.
You can see we this because we don't
have any Lambda functions saved yet.
I'm gonna go ahead and click Get Started.
From here Lambda gives us a number of blueprints
for different kinds of functions.
You can see we can start with a blank one.
We have some blueprints for processing Dynamo DB tables.
For getting objects from S3.
You can see AWS Lambda supports various languages
like Python, Node JS and java.
In this example we're going to go
with a blank function and use Node JS.
I'm going to click blank function.
Just for the sake of this demo
I don't want any triggers yet.
So I'm gonna go next.
I'm gonna name this LambdaDemo.
Just give it a simple description.
I'm gonna make sure that I choose the Node JS 4.3 run time.
From here we have the choice of either editing code inline
or we can upload a zip file or pull one out of S3.
For the sake of this demo, I'm just gonna go ahead
and edit the code here inline.
From here you can see that we have a simple function
called exports.handler.
This is how we communicate back to the Lambda service
that this is the name of our function
that we want to execute.
So here for those of us that might not be familiar
with java script, we have a function declaration
which is assigned back to this particular variable.
From here I'm just going to say console.log.
I'm going to output the event variable
that we're capturing here so that we can
see whatever data goes in will come out here.
I'm gonna go ahead and scroll down here
and say yes our handler is the dot handler function.
Now in order for the Lambda service
to be executed we need a role.
I'm gonna go ahead and hit create new role from template.
I'm going to say also call this one LambdaDemoRole.
Policy template...
I'm going to choose simple microservice permissions.
I don't need a whole lot of memory.
This particular demo doesn't require a whole lot,
probably even less than that.
But you can see that we can go up to quite a bit of memory.
One-and-a-half gigs if we need to.
I'm gonna choose that.
We could give this a longer time out if we wanted to.
I think probably 30 seconds would suffice.
10 seconds would actually suffice.
We don't need access to a VPC.
Lambda does give us that option.
If we want Lambda to communicate to services
running in a VPC, we could select one here
if we wanted to, but we don't for this demo.
I'm gonna go ahead and hit next.
Review all of that; that all looks good.
I'm gonna go ahead and hit create function.
There we go; now we have our function.
I can come back here to the configuration
and change those things if I need to.
In the code tab we can modify our code if we wanted.
I'm gonna come up here and configure a test event.
You can see we have a key value pair JSON object.
I'm going to get rid of some of these things here.
You'll see that it's yelling at us about our syntax
but as soon as we fix it.
There we go.
I'm gonna change this key to message.
I'm going to say Hello World.
Down here I'm going to go ahead and hit save.
That will be what we just edited.
That object will be given to this function
at the time we invoke or execute this function,
that object we just edited will be passed in
and captured as the event variable.
Then we're going to console log that here.
I'm gonna go ahead and hit test.
You can see that the output of the function,
the very last thing was said was Hello Lambda.
If we look at the log output we can see here
that this was our message in the code.
Initial execution and then the object that was passed in.
What I'm gonna do is I'm gonna change this a little bit.
Now the callback, this particular function you can see
is also passed in.
The callback is how when we execute that
that's how we inform the Lambda service
that our code, that our function is finished.
We're calling an asynchronous function
so that we can wrap things up.
Here I'm going to, instead of hard coding a message,
I'm going to leverage the message
that has passed in by the event.
I'm going to say callback null,
meaning no errors were given.
We're going to say event.message.
I'm going to say let's save and test this at the same time.
There we go; now our message
that we added to the event.message object
is output here as a result of the callback.
If we go to the logs, we can see that we also
got our console log out there again as well.
We can also see that it took 197 milliseconds to run that.
We were billed for 200 milliseconds.
We only used 8 megs of memory.
That is a Hello World example
of AWS Lambda server list infrastructure.
There were no EC2 instances to maintain,
or create, or worry about.
We just uploaded a function and the AWS Lambda service
handled it for us.