tencent cloud

Serverless Cloud Function

Release Notes and Announcements
Release Notes
Announcements
User Guide
Product Introduction
Overview
Related Concepts
How It Works
Strengths
Scenarios
Related Products
Purchase Guide
Billing Overview
Billing Mode
Billable Items and Billing Modes
Function Computing Power Support
Free Tier
SCF Pricing
Billing Example
Payment Overdue
Getting Started
Creating Event Function in Console
User Guide
Quota Management
Managing Functions
Web Function Management
Log Management
Concurrence Management
Trigger Management
Function URL
A Custom Domain Name
Version Management
Alias Management
Permission Management
Running Instance Management
Plugin Management
Managing Monitors and Alarms
Network Configuration
Layer Management
Execution Configuration
Extended Storage Management
DNS Caching Configuration
Resource Managed Mode Management
Near-Offline Resource Hosting Model
Workflow
Triggers
Trigger Overview
Trigger Event Message Structure Summary
API Gateway Trigger
COS Trigger
CLS Trigger
Timer Trigger
CKafka Trigger
Apache Kafka Trigger
MQTT Trigger
Trigger Configuration Description
MPS Trigger
CLB Trigger Description
TencentCloud API Trigger
Development Guide
Basic Concepts
Testing a Function
Environment Variables
Dependency Installation
Using Container Image
Error Types and Retry Policies
Dead Letter Queue
Connecting SCF to Database
Automated Deployment
Cloud Function Status Code
Common Errors and Solutions
Developer Tools
Serverless Web IDE
Calling SDK Across Functions
Third-Party Tools
Code Development
Python
Node.js
Golang
PHP
Java
Custom Runtime
Deploying Image as Function
Web Framework Development
Deploying Framework on Command Line
Quickly Deploying Egg Framework
Quickly Deploying Express Framework
Quickly Deploying Flask Framework
Quickly Deploying Koa Framework
Quickly Deploying Laravel Framework
Quickly Deploying Nest.js Framework
Quickly Deploying Next.js Framework
Quickly Deploying Nuxt.js Framework
Quickly Deploying Django Framework
Use Cases
Overview
Solutions with Tencent Cloud Services
Business Development
TRTC Practices
COS Practices
CKafka Practice
CLS
CLB Practice
MPS
CDN
CDWPG
VOD
SMS
ES
Scheduled Task
Video Processing
Success Stories
Tencent Online Education
Online Video Industry
Tencent Online Education
Best Practice of Tencent IEG Going Global
API Documentation
History
Introduction
API Category
Making API Requests
Other APIs
Namespace APIs
Layer Management APIs
Async Event Management APIs
Trigger APIs
Function APIs
Function and Layer Status Description
Data Types
Error Codes
SDK Documentation
FAQs
General
Web Function
Billing FAQs
Network FAQs
Log FAQs
SCF utility class
Event Handling FAQs
API Gateway Trigger FAQs
Related Agreement
Service Level Agreement
Contact Us
Glossary

Deploying Web Function on Command Line

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2024-12-02 20:07:18

Overview

Web function is a new function capability in SCF. Compared with event function that has limits on the event format, web function focuses on optimization of web service scenarios and can directly send HTTP requests to URLs to trigger function execution. For more information, please see Function Overview.
The Serverless Framework SCF component now supports deploying web functions; therefore, you can use it to quickly create and deploy web functions.

Directions

1. Run the following command to initialize the serverless web function template.
sls init http-demo
2. Enter the demo project and view the directory structure as shown below:
. http-demo
├── serverless.yml # Configuration file
├── package.json # Dependency file
├── scf_bootstrap # Project bootstrap file
└── index.js # Service function
Here, scf_bootstrap is the project bootstrap file. For the specific writing rules, please see Bootstrap File Description.
3. Open serverless.yml to view the configuration information. You only need to add the type parameter in yml to specify the function type and deploy the web function.
Note:
For web functions, there is no need to specify the entry function.
If the type parameter is not entered, the function will be an event function by default.
If there is no scf_bootstrap bootstrap file in the local code, you can specify the entryFile parameter in yml to specify the entry function, and the component will generate a default scf_bootstrap file for you to complete the deployment based on the runtime language. After the deployment is completed, you need to modify the content of the scf_bootstrap file in the SCF console according to the actual needs of your project.
Below is a sample yml file:
component: scf
name: http
inputs:
src:
src: ./
exclude:
- .env
# Specify web type as the function type
type: web
name: web-function
region: ap-guangzhou
runtime: Nodejs12.16
# For Node.js, you can enable automatic dependency installation
installDependency: true
events:
- apigw:
parameters:
protocols:
- http
- https
environment: release
endpoints:
- path: /
method: ANY

4. In the root directory, run sls deploy to complete the service deployment. Below is a sample:
$ sls deploy
serverless ⚡components
Action: "deploy" - Stage: "dev" - App: "http" - Name: "http"
type: web
functionName: web-function
description: This is a function in http application
namespace: default
runtime: Nodejs12.16
handler:
memorySize: 128
lastVersion: $LATEST
traffic: 1
triggers:
-
NeedCreate: true
created: true
serviceId: service-xxxxxx
serviceName: serverless
subDomain: service-xxxxxx.cd.apigw.tencentcs.com
protocols: http&https
environment: release
apiList:
-
path: /
method: ANY
apiName: index
created: true
authType: NONE
businessType: NORMAL
isBase64Encoded: false
apiId: api-xxxxxx
internalDomain:
url: https://service-xxxx.cd.apigw.tencentcs.com/release/
18s › http › executed successfully


Relevant Commands

Viewing access log

Similar to event function, you can directly run the sls log command to view the latest 10 logs of the deployed function. Below is a sample:
$ sls log
serverless ⚡components
Action: "log" - Stage: "dev" - App: "http" - Name: "http"
-
requestId: xxxxx
retryNum: 0
startTime: 1624262955432
memoryUsage: 0.00
duration: 0
message:
"""
"""
-
requestId: xxxxx
retryNum: 0
startTime: 1624262955432
memoryUsage: 0.00
duration: 0
message:
"""
"""

Testing service

Scheme 1: directly open the output path URL in a browser, and if it can be accessed normally, the function is successfully created, as shown below:


Scheme 2: use other HTTP testing tools such as CURL and Postman to test the web function you have successfully created. Below is a sample test with CURL:
curl https://service-xxx.cd.apigw.tencentcs.com/release/

Deleting service

Run the following command to remove your deployed cloud resources.
sls remove


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백