Setup Basic Serverless Project

Learn to set up a basic Serverless Framework project from scratch.

We'll cover the following

In this lesson, we'll focus on creating a basic Serveless project, which we'll then use in further lessons.

In the serverless.yml file, we define the configurations and resources needed for our Serverless project. This file is crucial as it provides the Serverless Framework with instructions on how to deploy and manage the resources for our application.

When we start with an empty serverless.yml file, we need to add the following components:

  • service: This is where we specify the name of the service, which is a logical grouping of all the related resources and functions. In our case, we name it sweet-factory.

  • provider: The provider section includes details about the cloud service provider, such as the name and the runtime environment. For our sweets factory project, we use AWS as the provider, and Node.js as the runtime (specifically, version 18.x).

  • functions: This section is where we list all the AWS Lambda functions that will be part of our service. Each function will have a unique name and a handler, which points to the corresponding TypeScript file and exported function. In the initial setup, we create a hello function with its handler set to handler.hello. This points to the hello function exported in the handler.ts file.

  • plugins: We can also extend the functionality of the Serverless Framework using plugins. Plugins are community-driven modules that enhance the capabilities of the framework, providing support for additional features or integrations with other services. For our sweets factory project, we'll use the serverless-esbuild plugin to enable the use of the esbuild bundler.

Adding these components to the serverless.yml file will create the foundation for our Serverless project. As we progress through the course and build the sweets factory production line, we'll expand the serverless.yml file to include more Lambda functions, integrate with other AWS services, and define additional configurations or resources needed for the application.

For instance, we might add a DynamoDB table for storing ingredient information, configure API Gateway to trigger specific Lambda functions, or define custom IAM roles for accessing other AWS resources.

By customizing the serverless.yml file, we ensure that the Serverless Framework can deploy, manage, and orchestrate all the resources and functions needed for our automated sweets factory production line.

Project setup

We have prepared the design in the widget below. There are two files:

  • A package.json file with the necessary libraries.

  • An empty serverless.yml file in which we'll work.

  • A folder for handlers with an empty handler.ts file where our Lambda function code will be stored.

Let's start the work by switching on the terminal, clicking the “Run” button, and waiting a minute for everything to load and install.

Get hands-on with 1200+ tech skills courses.