‫So now, let's talk about SAM,
‫the Serverless Application Model.
‫Now, this is really cool because we are going to view
‫how SAM regroups all the serverless development
‫we've seen so far into one single tool.
‫So SAM is this little squirrel,
‫and it means Serverless Application Model.
‫It's a framework that is going to be used to develop
‫and deploy serverless applications,
‫and all the configuration is going to be done in YAML.
‫Now, the idea is that from this simple YAML,
‫you're going to generate
‫very complex CloudFormation templates using the SAM CLI.
‫And because this is compatible with CloudFormation,
‫then any CloudFormation constructs work.
‫For example, outputs, mappings, parameter, resources,
‫all of these work within SAM.
‫Now, it's only two commands to deploy to AWS,
‫and you have to know them, so I will go over them,
‫and the exam will test you on them.
‫And then, we'll see in another lecture,
‫SAM can use CodeDeploy to deploy Lambda functions
‫and make sure we have gradual shift of traffic
‫between our Lambda function versions.
‫Finally, and we'll see this in this lecture,
‫SAM can help you run Lambda,
‫API Gateway, and DynamoDB locally,
‫so you don't need to deploy to AWS
‫to start testing your applications.
‫So, what is a recipe?
‫Well, SAM has a YAML template, and at the top of it,
‫you will find this transform header,
‫AWS Serverless 2016 10 13.
‫What it means is that this is a SAM template,
‫and then CloudFormation will be smart enough
‫to know how to transform this template
‫into a CloudFormation template.
‫So we're going to write some code then,
‫and there's some additional constructs provided
‫inside of the SAM YAML files.
‫So we can use an AWS Serverless Function,
‫which is going to be a Lambda function in the back end,
‫a Serverless Api, which is going to be API Gateway,
‫and a Serverless SimpleTable, which is a DynamoDB table.
‫So these are meant to help you go faster
‫at creating functions, databases, and API gateways.
‫And next, to package and deploy SAM, two commands.
‫So the first one is aws cloudformation package,
‫or short, sam package,
‫and then the second one is aws cloudformation deploy,
‫or the shorthand version is sam deploy.
‫So this is as simple as that.
‫The exam will say, how do I deploy?
‫The first one is sam package,
‫and the second one is sam deploy.
‫Let's have a look at these commands in deep dive.
‫So we have a SAM template, which is written in YAML,
‫and our application code,
‫and we're going to do a sam build
‫to build the application locally,
‫and it's going to create
‫a transformed CloudFormation template
‫and our application code.
‫And then, we're going to run sam package,
‫or aws cloudformation package,
‫to zip and upload our function
‫and have it uploaded into an S3 bucket.
‫So both the CloudFormation template
‫and our application code is going to be uploaded.
‫And then, using the sam deploy command,
‫we're going to deploy our application.
‫From the S3 bucket, it's going to create
‫and execute a ChangeSet onto CloudFormation
‫to start deploying our application.
‫And then, CloudFormation will deploy our Lambda functions,
‫our API gateways, and DynamoDB.
‫So very important to see the process.
‫So SAM template gets transformed
‫into CloudFormation with sam build,
‫then packaged into Amazon S3 using the sam package command,
‫and then deployed onto CloudFormation
‫using the sam deploy command.
‫If you really understand this diagram,
‫you will have most of the SAM questions figured out
‫at the exam.
‫Another question you can have is,
‫how can you run Lambda locally?
‫Well, to run Lambda functions locally,
‫you can use the SAM CLI
‫because the SAM CLI has the power to provide you
‫with a Lambda-like execution environment locally.
‫How does it do it?
‫Well, we use the SAM CLI and AWS Toolkits,
‫which are going to allow us
‫to step through our code and debug it.
‫So instead of deploying a Lambda function on the cloud
‫and then stepping through it
‫or trying to find where it failed,
‫you can do all the development that you're used to do
‫directly on your local computer without deploying to AWS.
‫So the SAM CLI has toolkits for various different IDEs.
‫So we have Cloud9, Visual Studio Code, JetBrains,
‫PyCharm, IntelliJ, and so on.
‫And both these things together allow us
‫to run a Lambda function locally on our computer
‫and then use our favorite tools to debug locally,
‫for example, to do a step-through of the code line by line.
‫And so these toolkits is what is giving SAM the power
‫to invoke Lambda locally, okay?
‫So that's it for an intro to SAM. I hope you liked it.
‫And in the next lecture, we'll have a play with it.