Operation Scenarios
This document describes how to use the SCF component provided by Serverless Framework to quickly create and deploy an SCF project.
Prerequisites
Directions
Creating function directory
1. Run the following command on the command line to create a directory and enter it (this document uses tencent-scf
as an example):
mkdir tencent-scf && cd tencent-scf
2. Run the following commands in sequence to quickly create an SCF application:
serverless create --template-url https://github.com/serverless-components/tencent-scf/tree/v2/example
After the application is created successfully, its directory structure is as follows.
|- src
| └── index.py
└── serverless.yml
Deploying function
1. Enter the directory where serverless.yml
is and run the following command to deploy the function:
2. Log in to your Tencent Cloud account and grant applicable permissions. If you want to configure persistent environment variables or key information, please do so as instructed in Account Configuration.
After the function is deployed successfully, you can view the URL provided by the gateway trigger of the corresponding function in the command line output and access the URL in a browser to view the function deployment result. Note:
If you want to view more information on the deployment process, you can run the sls deploy --debug
command to view the real-time log information during the deployment process (sls
is an abbreviation for the serverless
command).
Configuring deployment
The SCF component supports "zero" configuration deployment, that is, it can be deployed directly with the default values in the configuration file. Nonetheless, you can also modify more optional configuration items as needed to further customize the project to be deployed.
The following is the description of the SCF component configuration file serverless.yml
. For more information, please see Full Configuration and Configuration Description.
component: scf
name: scfdemo
org: test
app: scfApp
stage: dev
inputs:
name: scfFunctionName
src: ./src
runtime: Nodejs10.15
region: ap-guangzhou
handler: index.main_handler
events:
- apigw:
name: serverless_api
parameters:
protocols:
- http
- https
serviceName:
description: The service of Serverless Framework
environment: release
endpoints:
- path: /index
method: GET
After updating the fields in the configuration file, run the serverless deploy
or serverless
command again to update the configuration to the cloud.
Subsequent Operations
After deploying the function, you can use the development and debugging capabilities provided by the component to re-develop the project into a production-ready application.
Was this page helpful?