‫So to initialize our project, we could run
‫sam init, and I'll just have the help function here.
‫And sam init basically generates a SAM project for you
‫and you can specify the run time you want being python 3.6,
‫but you could also say 2.7, node js, and so on.
‫Sam init creates a lot of files for you
‫and I don't want to overwhelm you, so how about we just go
‫one by one, we don't use sam init, we're just going
‫to create the code one file at a time
‫so it makes a lot of sense for us.
‫So just to make things easy, I'm going to have
‫a source folder and the source folder will contain
‫our application so I'll call it
‫a new file and I'll make a app.py file,
‫I'll just write my application in Python.
‫That's going to be our source folder.
‫We're also going to need to have a template file
‫so we'll have template.yaml and this is going to be
‫our SAM file so SAM file right here.
‫And finally we're going to have to write
‫our commands somewhere so I'll just say them,
‫I'll have a commands.sh file.
‫So now we need to go ahead and fill the app.py,
‫sample.yaml...uh, template.yaml, and so on.
‫So this, let's just go straight to
‫the server application model example apps
‫because that will be the easiest way
‫for us to make sense of everything.
‫And let's find a hello world python three.
‫That sounds great, and here we have a lambda_function.py
‫and a template.yaml, so let's open these two in two tabs
‫and let's first look at the lambda_function.py.
‫So this is a very easy lambda function, imports
‫to json package and returns some events.
‫So let's just go and import that function
‫and I'll just have this into my source, app.py.
‫So here this is the basic lambda function
‫that we have from before and I'm actually going to remove
‫a lot of stuff as well from here and I'm just going
‫to say return "Hello World," and that's about it.
‫Okay, a very simple lambda function.
‫Now, let's do the more fun stuff,
‫which is to take care of this template.yaml file.
‫So template.yaml file, let's go back and here it is,
‫it is going to be the yaml file that will
‫describe how your function should be.
‫So let me copy this entire thing
‫and we'll analyze the lines one by one.
‫I'll copy the yaml file right here and here we go.
‫The first thing, the first line
‫is the AWStemplateformatversion.
‫It says 2010, so this is just indicating
‫this is a cut formation template.
‫The second thing is a transform, and a transform
‫is indicative that we are using a sam template,
‫because the transform says "AWS Serverless 2016-10-31."
‫So this is what you would see at the exam.
‫Any time you would see a transform
‫saying this, that means it's a sam template.
‫Now we can have description, and that's our
‫starter AWS lambda function, we could have some parameters,
‫but I'm actually going to remove
‫these parameters to make it very simple.
‫And so we have the first resource which
‫is the helloworldpython3, the type of it
‫is a serverless function, and this is a sam-specific type
‫of resource, and we can look at properties.
‫Properties is that our lambda function
‫is going to have a handler.
‫Now the handler should be
‫the file name dot the function name.
‫Turns out that our file name is app.py, not lambda_function.
‫So I'll just change this to app.
‫And within our app, the py, the first function we define,
‫is lambda_handler, so I'll keep app.lambda_handler.
‫The runtime is python3.6, and the code is not
‫in this directory, it is in the source directory,
‫so I'll just have source as the CodeUri.
‫CodeUri indicates locally where the code is.
‫For me it is in the source directory.
‫Now the description is that it's our starter AWS function.
‫We can define the memory size straight
‫from our parameters, so can we for the timeouts.
‫And for the policies, I need to remove
‫this because it is not useful right now.
‫So here is our most simple file
‫for sam, it looks pretty simple.
‫We have a template, an app.py, and then we need
‫to deploy it, which I will do in the next lecture.