Serverless Framework uses the project configuration file serverless.yml
to identify the application type and configure the resources. After you develop a project locally, you must configure the .yml
file first before you can deploy the project in the cloud by running the sls deploy
command to pass the configuration information in serverless.yml
and the specified parameters or code directory in inputs
to the Serverless Components deployment engine.
The first-level field in a basic serverless.yml
file is configured as follows:
# Organization information (optional)
app: '' # Application name. If it is left empty, the instance name of the current component will be used by default
stage: '' # Environment name. The default value is `dev`. We recommend you use the `${env.STAGE}` variable to define the environment name
# Component information
component: scf # Component name, which is required. It is `scf` in this example
name: scfdemo # Component instance name, which is required
# Component parameter configuration, which configures specific resource information for each component
inputs:
In the inputs
field, the corresponding information will be configured for the resources created by each component in the cloud. The SCF Component is taken as an example here. The second-level directory in the input
field is as follows:
inputs:
name: xxx # Function name, which is `${name}-${stage}-${app}` by default
src: ./src # Project code path in the default format. Create a specifically named COS bucket and upload it
handler: index.main_handler # Entry
runtime: Nodejs10.15 # Runtime environment, which is Nodejs10.15 by default
region: ap-guangzhou # Function region
description: This is a function in ${app} application.
environment: # Environment variable
variables: # Environment variable object
TEST: value
layers: # Layer configuration
- name: scfLayer # Layer name
version: 1 # Version
events: # Trigger configuration
- timer: # Scheduled trigger
parameters:
cronExpression: '*/5 * * * * * *' # Trigger once every 5 seconds
enable: true
Below is the list of full configuration information for each component of Serverless Framework:
Component | Full Configuration |
---|---|
SCF | SCF - serverless.yml configuration |
Website | Website - serverless.yml configuration |
API Gateway | API Gateway - serverless.yml configuration |
VPC | VPC - serverless.yml configuration |
COS | COS - serverless.yml configuration |
PostgreSQL | PostgreSQL - serverless.yml configuration |
CynosDB | CynosDB - serverless.yml configuration |
CDN | CDN - serverless.yml configuration |
Layer | Layer - serverless.yml configuration |
Component | Full Configuration |
---|---|
Express | Express - serverless.yml configuration |
Koa | Koa - serverless.yml configuration |
Egg | Egg - serverless.yml configuration |
Next.js | Next.js - serverless.yml configuration |
Nuxt.js | Nuxt.js - serverless.yml configuration |
Flask | Flask - serverless.yml configuration |
Django | Django - serverless.yml configuration |
Laravel | Laravel - serverless.yml configuration |
ThinkPHP | ThinkPHP - serverless.yml configuration |
Was this page helpful?