tencent cloud

All product documents
Serverless Application Center
Quickly Deploying a Function Template
Last updated: 2024-12-02 10:48:10
Quickly Deploying a Function Template
Last updated: 2024-12-02 10:48:10

Overview

This document describes how to use Serverless Cloud Framework to quickly create, configure, and deploy an Serverless Cloud Function (SCF) application on Tencent Cloud.

Prerequisites

You have installed Serverless Cloud Framework 1.67.2 or later. For more information, see Installing Serverless Cloud Framework.
You have signed up for a Tencent Cloud account as instructed in Signing Up.
Note
If your account is a Tencent Cloud sub-account, first get the authorization from the root account as instructed in Account and Permission Configuration.

Directions

Quick deployment

In an empty folder directory, run the following command:
serverless-cloud-framework
Next, initialize the project as prompted. Select the scf-starter template for the application and select the runtime you want to use (Node.js is used as an example here):
serverless-cloud-framework: No Serverless project is detected. Do you want to create a project? Yes
serverless-cloud-framework: Select the Serverless application you want to create: scf-starter - quickly deploys an SCF function

react-starter - quickly deploys a React.js application
restful-api - quickly deploys a RESTful API to use Python + API Gateway
❯ scf-starter - quickly deploys an SCF function
vue-starter - quickly deploys a basic Vue.js application
website-starter - quickly deploys a static website
eggjs-starter - quickly deploys a basic Egg.js application
express-starter - quickly deploys a basic Express.js application

serverless-cloud-framework: Select the runtime of the application: scf-nodejs - quickly deploys an SCF function in Node.js

scf-golang - quickly deploys an SCF function in Go
❯ scf-nodejs - quickly deploys an SCF function in Node.js
scf-php - quickly deploys an SCF function in PHP
scf-python - quickly deploys an SCF function in Python

serverless-cloud-framework: Enter the project name: demo
serverless-cloud-framework: Installing the scf-nodejs application...

scf-nodejs › Created


The demo project has been successfully created!
Click Deploy Now to quickly deploy the initialized project to the SCF console:
serverless-cloud-framework: Do you want to deploy the project in the cloud now? Yes

Click the link below to log in:
https://slslogin.qcloud.com/********
Logged in successfully!

serverless-cloud-framework
Action: "deploy" - Stage: "dev" - App: "scfApp" - Name: "scf-nodejs"

code:
bucket: sls-cloudfunction-ap-guangzhou-code
object: /scf_component_******-**********.zip
description: This is a function in scfApp application
functionName: scf-nodejs-dev-scfApp
handler: index.main_handler
lastVersion: $LATEST
memorySize: 128
namespace: default
runtime: Nodejs10.15
sourceCodeDownloadUrl: https://sls-app-code-prod-**********.cos.ap-guangzhou.myqcloud.com/***
triggers:
-
NeedCreate: true
apiList:
-
apiId: api-********
apiName: index
authType: NONE
businessType: NORMAL
created: true
isBase64Encoded: false
method: GET
path: /
created: true
environment: release
protocols: http
serviceId: service-********
serviceName: serverless
subDomain: service-********-**********.gz.apigw.tencentcs.com
urls:
- http://service-********-**********.gz.apigw.tencentcs.com/release/
type: event

SCF console: https://serverless.cloud.tencent.com/apps/scfApp/scf-nodejs/dev

184s »scf-nodejs» Execution succeeded.
After deployment, complete the remote invocation of the function by running the following command:
scf invoke --inputs function=helloworld
Note
scf is short for serverless-cloud-framework.

Viewing the Deployment Information

To view the application deployment statuses and resources again, go to the directory that is successfully deployed and run the following command:
cd demo # Enter the project directory. Please change to your actual project's directory name here
scf info

Viewing the directory structure

In the directory of the initialized project, you can see the most basic structure of a serverless function project:
.
├── serverless.yml # Configuration file
├—— index.js # Entry function
└── .env # Environment variable file
The serverless.yml configuration file implements the quick configuration of the basic function information. All the configuration items supported by the SCF console can be configured in the .yml file. For more information, see SCF Configuration Information.
index.js is the entry function of the project, which is the helloworld template here.
The .env file stores user login authentication information. You can also configure other environment variables in it.

Redeployment

In the local project directory, you can modify the function template and configuration file and then redeploy the project by running the following command:
scf deploy
Note
To view the detailed information during removal, you can add the --debug parameter.

Continuous development

After the deployment is completed, Serverless Cloud Framework allows you to run different commands to implement capabilities such as continuous development and grayscale release for the project. You can also use this component in conjunction with other components to manage the deployment of multi-component applications.
For more information, see Application Management and List of Supported Commands.

FAQs

Question 1: What should I do if the wizard does not pop up by default after I enter serverless-cloud-framework .
Solution: Add the SERVERLESS_PLATFORM_VENDOR=tencent configuration to the .env file.
Question 2: What should I do if the deployment is very slow in an overseas network after I enter sls deploy ?
Solution: Add the GLOBAL_ACCELERATOR_NA=true configuration to the .env file to accelerate the overseas network.
Question 3: What should I do if a network error occurs during deployment after I enter scf deploy ?
Solution: Add the following proxy configurations to the .env file.
HTTP_PROXY=http://127.0.0.1:12345 # Replace "12345" with your proxy port
HTTPS_PROXY=http://127.0.0.1:12345 # Replace "12345" with your proxy port

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon