Rich Buggy: To create a new project, I'll use the sam init command with the -r option to set the run time to nodejs10.x and -n to create it in a new folder called demo.
Once the project is being created, I'll open it up in my editor. The template.yaml file contains the cloud formation configuration for my project. In the resources section, the default template includes one function called HelloWorld.
The code for the handler for my function is located in the app.js file in the Hello World folder. To build the project, use sam build.
Once you've build the application, you need to upload it to S3 for deployment using sam package command. The name of the S3 deployment bucket is set using the S3 bucket option.
Sam package will create a version of your template.yaml file with the local files replaced with the S3 URLs. To save that, I will use the app with template option and call the output file, packaged.yaml. You also need to provide the name of the AWS profile and the region.
Once the project has been packaged, you can deploy using the sam deploy command. For the template file option, you need to use to file that was created by sam package.
In this example, I'll use the stack name option to name my stack demo. I also need to set capabilities to CAPABILITY_IAM. Finally, I need to set the AWS profile to use for deployment and the region to deploy it to.
Once that project has being deployed, we can go a CloudFormation in the AWS Console and you'll see the new stack. Clicking on the stack name shows me the details for that particular stack. In the Events, you can see what happened during deployment. This is useful if something goes wrong and you need to debug the problem.
In the Resources tab, you'll see the resources that were created in your AWS account during the creation of CloudFormation stack. Clicking on the physical ID next to HelloWorldFunction, will take me to the Lambda console for the HelloWorldFunction.
You can see that the HelloWorldFunction is triggered by the API Gateway. If I click on API Gateway, I can then see the URL for the API endpoint that will trigger my Lambda. Clicking on this opens up the new window, and we can see the response from the Lambda, the message, "Hello World."