The development and launch process of a project is as shown below:
dev
branch for joint testing.During each stage of project development, an environment running independently is required to isolate the development operations.
Define stage
in the serverless.yml
file and write stage
into the component's resource names as a parameter, so that resources named instance name-{stage}-application name
will be generated during the deployment. In this way, you can generate different resources in different stages by defining different stage
values so as to isolate the environments.
Take serverless.yml
of the SCF component as an example:
# Application information
app: myApp
stage: dev # The environment is defined as `dev`
# Component information
component: scf
name: scfdemo
# Component parameters
inputs:
name: ${name}-${stage}-${app} # Function name. The `${stage}` variable is used as a part of the resource name
src: ./
handler: index.main_handler
runtime: Nodejs10.15
region: ap-guangzhou
events:
- apigw:
parameters:
endpoints:
- path: /
method: GET
name
as ${name}-${stage}-${app}
.stage
as dev
for the development and testing stages. After the deployment, the function will be named scfdemo-dev-myApp
.stage
as pro
for the release stage. After the deployment, the function will be named scfdemo-pro-myApp
.Note:
You can directly define
stage
in theserverless.yml
file or pass in the parameter throughsls deploy --stage dev
.
During project development, you need to assign permissions to different persons and manage their permissions; for example, you want a developer to access only a certain environment in a project. To this end, you can grant sub-accounts permissions to manipulate specified resources in Serverless Framework as instructed in Account and Permission Configuration.
Taking the dev
environment of the myApp
project as an example, the configuration is as follows:
{
"version": "2.0",
"statement": [
{
"action": [
"sls:*"
],
"resource": "qcs::sls:ap-guangzhou::appname/myApp/stagename/dev", # `app` is `myApp`, and `stage` is `dev`
"effect": "allow"
}
]
}
Grayscale release (aka canary release) is a release method that can smoothly transition between black and white. To guarantee the stability of your business in the production environment, we recommend you use grayscale release to launch projects in the production environment.
Grayscale release for serverless applications is applicable only to the SCF component and relevant components involving SCF.
You can configure the traffic rule of the SCF function whose alias is $default
(default traffic) to configure the traffic of two function versions, where one is the $latest
version of the function, while the other is the last published version. For more information, please see Grayscale Release.
From project development to release, you need to use relevant Serverless Framework commands. For more commands, please see List of Supported Commands.
# Initialize the project
sls
# Download the template project `scf-demo`. You can run `sls registry` to query the available templates
sls init scf-demo
# Download the template project `scf-demo` and initialize it as `myapp`
sls init scf-demo --name my-app
# Deploy the application
sls deploy
# Deploy the application and specify `stage` as `dev`
sls deploy --stage dev
# Deploy the application and print the deployment information
sls deploy --debug
# Deploy and publish the function version
sls deploy --inputs publish=trues
# Deploy and switch 20% traffic to the `$latest` version
sls deploy --inputs traffic=0.2
For more information, please see Developing and Launching Serverless Application.
Was this page helpful?