Introduction to AWS SAM and Installation and Initialization of Project
So,the buzz around the keyword “Serverless” caught you,after all. Welcome onboard ! — There is a lot to explore.
One of the first decisions that you’d have to make is choice of deployment framework. The official framework to deploy applications by AWS is Serverless Application Model(SAM).
I myself started serverless development just 3 months back. Before the introduction of SAM, I was using the traditional way of zipping the Lambda code(deployed on local) and pushing to Lambda function using command line. I had seriously no way of debugging my NodeJS code running on local.
With SAM, some of the benefits that I found —
- Single-deployment configuration
- Local debugging and testing
To get SAM working on your machine, you need to -
- Install SAM CLI —
The AWS SAM CLI is mandatory to start your SAM journey. Download MSI for windows here.
- Install Docker —
Docker Desktop supports the most recent Windows operating system. Download here.
- Configure Shared drives —
The AWS SAM CLI requires that the project directory, or any parent directory, is listed in a shared drive. To share drive on Windows 10, follow these articles :
- Verify the installation
After Docker is installed, verify that it’s working. Also confirm that you can run Docker commands from the AWS SAM CLI (for example,
docker ps). You don't need to install, fetch, or pull any containers––the AWS SAM CLI does this automatically as required.
Initialization of Project
The runtime that we will be using to setup the project is NodeJs. But you can initialize project for nearly any provided runtime.
sam init — runtime nodejs8.10
You can change to any runtime of your preference. Possible options are
nodejs8.10, dotnetcore, go1.x, ruby, ruby2.5, python2.7, nodejs, python3.6, dotnet, java8, python, dotnetcore1.0, dotnetcore2.1, go, dotnetcore2.0, nodejs10.x, java, nodejs6.10, python3.7
SAM provides some more options at the time of initializing a project. I would suggest you to explore them as per you needs. Please click here.
Now, if everything worked correctly for you, the project structure should look like —
“hello-world” is the main folder that contains all our code and files for development. “app.js” contains the exports handler.If you are from the JS background, rest of files are self explainatory except —
- event.json : This file contains the JSON that we pass as request body to our API Gateway or you can take it as Test Cases in Lambda for testing.
- template.yaml : This is the heart of our SAM project. Consists of all the configurations,IAM role permissions to out project, handler name etc.
So,That’s it guys for this blog. In the next upcoming blog of SAM series, we will develop, debug and publish our SAM project as a Lambda function with just a few commands. Stay tuned ! I will update the new blog’s link here.
Please clap if this article helped you and I am always open to suggestions.