Tencent Cloud Egg.js Serverless Component supports deploying RESTful API services.
mkdir serverless-egg && cd serverless-egg npm init egg src --type=simple cd src && npm install
Use npm to install Serverless CLI globally:
npm install -g serverless
serverless.yml file in the project root directory:
serverless.yml file as follows (for more information on the configuration of the .yml file, please see Configuration Information):
component: egg name: eggDemo app: appDemo inputs: src: ./ region: ap-guangzhou runtime: Nodejs10.15 apigatewayConf: protocols: - http - https environment: release
Deploy by running the
sls deploy command, and you can add the
--debug parameter to view the information during the deployment process:
slsis short for the
sls deploy MyComponent: region: ap-beijing functionName: egg-function apiGatewayServiceId: service-n5m5e8x3 url: https://service-n5m5e8x3-1251971143.bj.apigw.tencentcs.com/release/ 32s › MyComponent › done
You can run the following commands to remove the deployed API Gateway and SCF services:
sls remove --debug DEBUG ─ Flushing template state and removing all components. DEBUG ─ Removing function DEBUG ─ Request id DEBUG ─ Removed function egg-function successful DEBUG ─ Removing any previously deployed API. api-cmkhknda DEBUG ─ Removing any previously deployed service. service-n5m5e8x3 8s › MyComponent › done
Currently, you can scan a QR code to log in to the CLI by default. If you want to configure persistent environment variables/key information, you can also create a local
touch .env # Tencent Cloud configuration information
Configure Tencent Cloud's
SecretKey information in the
.env file and save it:
# .env TENCENT_SECRET_ID=123 TENCENT_SECRET_KEY=123
What should I do if the
app/public deployment directory does not exist?
Generally, when you initialize an Egg.js project, the
app/public directory will be created automatically. If this directory is empty during packaging and compressing, it will not exist after the deployment; instead, it will automatically be created when the Egg.js project is started; however, SCF will not have the permission to manipulate it. Therefore, we recommend you create an empty folder
.gitkeep in the
app/public directory to solve this problem.
What should I do if a failure to find the dependent module is reported after deployment with Layer?
For more information, please see here.
You can view more component information in the repository of Serverless Components.