AWS Lambda

Tram Ho

What is serverless

Serverless allows you to build and run applications and services without having to worry about the server. Understand simply that you only need to care about writing code to solve customer problems and push the code onto a service (AWS Lambda) to run without caring about server building.

Serverless allows you to build modern applications with greater flexibility and lower total cost of ownership. Building serverless applications means that developers can focus on the core product instead of having to worry about managing and operating multiple servers or runtime, whether on cloud or on-premises.

AWS Lambda

AWS Lambda allows you to run code without providing or managing servers. Just upload your code and Lambda will take care of everything it needs to run. Lambda supports languages: Node.js, Python, Java, Ruby, C #, Go and PowerShell.

What is the AWS Serverless Application Model (AWS SAM)

AWS Serverless Application Model (AWS SAM) is an open source framework for building serverless applications, used to run on AWS ( )


Before installing you must set the following conditions:

  1. Install docker on the operating system
  2. AWS account (to deploy code)

Next, install Homebrew as a package manager. See details here . Run the following commands to install

Add Homebrew to PATH on linux with the following command:

Check if the installation was successful

Results displayed

Finally install the SAM cli with the following command:

Check if installed

Hello World Application

In this article I will use the Nodejs language to write services. To initialize the project we will run the following command:

Results after running the command

Or to initialize with other options you can refer here

After the project has been created, I have modified the directory structure as follows:

The app.js file will take responsibility for receiving requests from the API and the response for the following content

Folder service will contain utils file to handle the business tasks of the task. For the time being I won't have any complicated functions, so I'll leave it blank

Edit template.yml file

I will explain a little bit about conifg above

  • CodeUri: used to specify the folder containing source code
  • Handler: function will contain the code to start when starting running
  • Runtime: runtime environment
  • MemorySize: ram capacity when running docker
  • Timeout: the maximum time to run the program
  • Events: declares api endpoints

Run the following command to start API Gateway Locally

Results after starting api:

Check if the API has a response:


You can refer to your project on github:

Share the news now

Source : Viblo