“Introduction”

Earlier, I wrote an article about owning your own cloud server, CVM, and documented how to buy a cloud host and deploy your code to the Internet.

While low-spec cloud servers are cheap, they still cost money. If you just want to publish your project to the Internet so that all users can visit, I recommend the real whoring service resources “Tencent cloud Serverless cloud function”.

Moreover, Serverless cloud function does not require developers to know server-related knowledge, and only need to follow the configuration provided by Tencent Cloud Serverless to complete the deployment of the project. Do not understand the front-end server knowledge of the students is really friendly.

The point is that the current can completely white whoring, Tencent cloud provides a strong free amount, love to play friends can try

Introduction to Serverless

Serverless website

“Serverless”

Serverless is where the server-side logic is implemented by the developer, runs in a stateless computing container, is triggered by events, is completely managed by a third party, and its business-level state is stored in a database or other media.

Serverless is an advanced stage in the evolution of cloud native technologies that allow developers to focus more on business logic and less on infrastructure.

Tencent Cloud Function

Serverless Cloud Function (SCF) is a Serverless execution environment provided by Tencent Cloud for enterprises and developers to help you run code without purchasing and managing servers. You only need to use the language supported by the platform to write the core code and set the conditions for the code to run, so that the code can run flexibly and safely on Tencent cloud infrastructure

Serverless characteristics

  • Lower running costs
  • Automatic capacity expansion and shrinkage
  • event-driven
  • statelessness

“All talk, no action”

1. Tencent Cloud Serverless supports mainstream development languages

Tencent Cloud Serverless supports python, PHP, Nodejs, Go, Java and other programming languages. The deployment process of Node12 will be recorded in detail.

2. Web static page hosting template

  1. Function name: Used to distinguish different cloud functions
  2. Runtime environment: Select the programming language for the code to be deployed (using Nodejs as an example)

3. Function configuration

Confirm the configuration information of cloud functions and add a project description for easy differentiation.

The code below is the template code to deploy to see.

4. Check whether the deployment is successful

The system provides a “test” function. If you try it, the “Execution summary” and “return result” contents show that the cloud function was successfully deployed.

But if we deploy a static server that doesn’t just look at responses, how can we access the page through the browser?

5. Trigger API gateway trigger for management

Deploying a static server, of course, renders the page in the most direct way possible, rather than showing the user the response message.

The Serverless cloud function provides multiple triggers

  • Timing trigger
  • COS the trigger
  • CMQ topic subscription triggers
  • Ckafka trigger
  • API gateway trigger

Create trigger: API gateway trigger


* * access API gateway triggers create success, address: service-1ssdjrj6-1253629794.gz.apigw.tencentcs.com/release/ser…

6. Access effect

“Serverless Deployment Koa Project”

As a professional front-end programmer, I’m used to working on projects “from the command line.”

Tencent Serverless cloud function provides CLI command line tools for our operation.

  1. NPM global installation Serverless CLI
npm install -g serverless
Copy the code
  1. Initialize the project
SLS init koa-starter --name levenx-serverless-koa or serverless init koa-starter --name levenx-serverless-koaCopy the code

Severless supports a list of templates that you can replace according to your own needs

Command template: SLS init < template name > — name

Template List entry

  1. Vscode opens the project

Those of you who have played Koa will be familiar with the template code provided by Serverless Scaffolding, and of course you can modify the code as you wish

  1. Deploying cloud functions
sls deploy
Copy the code

When you run the Deploy command for the first time, you need to authorize wechat code scanning. After successful authorization, the vscode terminal can see the progress of the deployment until Success.

  1. Tencent Cloud Console

As with the previous template code deployment, set up the API gateway handler

Visit address:Service-el1maiby-1253629794.gz.apigw.tencentcs.com/test/koa_co…

  1. Access to the effect

Remark:

All come to this step, we should know how white whao Tencent Serverless cloud function

“Previous Articles recommended”

  • In this way, I have a cloud server of my own

Ordinary people are still hesitating, excellent you prepared for a key three link ~ 👋👋👋

Official account: “Enjoy the World”

🏆 issue 7 | all things can be Serverless technology projects