sls deploy
is run, a serverless application will be deployed, which consists of one or multiple component instances, and each component corresponds to an instance.serverless.yml
file, which defines certain parameters of the component. Such parameters are used to generate the instance information during deployment; for example, region
defines the resource region.serverless.yml
of the component.serverless.yml
in the project directory, so that all components can use the same application name.serverless.yml
file defines the application organization parameters and the component's inputs
parameters. During each deployment, resources will be created, updated, and orchestrated according to the configuration information in the serverless.yml
file.serverless.yml
file:# serverless.yml# Application informationapp: expressDemoApp # Application name, which is the component instance name by defaultstage: ${env:STAGE} # Parameter used to isolate the development environment, which is `dev` by default and optional# Component informationcomponent: express # Name of the imported component, which is required. The `express-tencent` component is used in this examplename: expressDemo # Name of the instance created by the component, which is required# Component configurationinputs:src:src: ./exclude:- .envregion: ap-guangzhouruntime: Nodejs10.15functionName: ${name}-${stage}-${app} # Function nameapigatewayConf:protocols:- http- httpsenvironment: release
.yml
file:Parameter | Description |
org | Organization information, which is the APPID of your Tencent Cloud account by default. It is a reserved field and is not recommended to be used. |
app | Application name, which is the same as the instance name in the component information by default. A single-instance application and a multi-instance application have different definitions of this parameter. For more information, please see Application Management. |
stage | Environment information, which is dev by default. You can define different stage values to provide independent runtime environments for development, testing, and release of the serverless application, respectively. For more information, please see Project Development. |
Parameter | Description |
component | Name of the imported component. You can run sls registry to query components available for import. |
name | Name of the created instance. An instance will be created when each component is deployed. |
inputs
are configuration parameters of the corresponding component. Different components have different parameters. To guarantee environment isolation and resource uniqueness, the component resource names are in the ${name}-${stage}-${app}
format by default.app
) in the serverless.yml
file, and an application with the same name as that of the instance (name
) will be generated by default during deployment.scfDemo|- index.js└── serverless.yml
serverless.yml
file is configured as follows:component: scfname: myscfinputs:src: ./runtime: CustomRuntimeregion: ap-guangzhoufunctionName: ${name}-${stage}-${app} # Function nameevents:- apigw:parameters:endpoints:- path: /method: GET
sls deploy
in the scfDemo
directory for deployment, and an application whose app
is myscf
will be generated by default, and the application will contain an SCF instance named myscf
.serverless.yml
as follows:app: scfApp # Set `app` to `scfApp`component: scfname: myscfinputs:src: ./runtime: CustomRuntimeregion: ap-guangzhouevents:- apigw:parameters:endpoints:- path: /method: GET
sls deploy
in the scfDemo
directory for deployment, and an application whose app
is scfApp
will be generated, and the application will contain an SCF instance named myscf
.serverless.yml
file in the root directory of the project to name the application.fullstack|- api| |- sls.js| |- ...| └── serverless.yml|- db| └── serverless.yml|- frontend| |- ...| └── serverless.yml|- vpc| └── serverless.yml|- scripts└── serverless.yml
app
is set in the serverless.yml
file in the fullstack
directory of the project:# Project application informationapp: fullstack
serverless.yml
file in each component directory, such as the api
directory:# `api` configuration informationcomponent: expressname: fullstack-apiinputs:src:src: ./exclude:- .envfunctionName: ${name}-${stage}-${app}region: ${env:REGION}runtime: Nodejs10.15functionConf:timeout: 30vpcConfig:vpcId: ${output:${stage}:${app}:fullstack-vpc.vpcId}subnetId: ${output:${stage}:${app}:fullstack-vpc.subnetId}environment:variables:PG_CONNECT_STRING: ${output:${stage}:${app}:fullstack-db.private.connectionString}apigatewayConf:enableCORS: trueprotocols:- http- https
app
) is written into all components, which requires you to ensure that all components under the project have the same application name. We recommend you not use this method in the new version.
Was this page helpful?