As a developer, you should understand that a website has to go through a lot of tedious steps from development to launch.

Writing code, deploying applications, deploying databases, applying for domain names, applying for SSL certificates, registering domain names, and finally going online takes at least a few days.

As a business player who is not proficient in code, when you want to play with a website, you will often be scared away by ridiculously valuable offers.

In recent years, the concept of Serverless has been very hot, as the name implies, “no service”. Today’s article, I want to stand in the perspective of a developer, with a simple experience under the use of Tencent cloud Serverless to develop the website’s overall process. See how much easier it is to develop a website under the concept of Serverless.

Main contents of this paper:

  • Serverless Concept description
  • Deploy a website in 3 minutes
  • Develop an online RSS reading site in 10 minutes
  • Analysis of advantages and disadvantages of Tencent Serverless Web Function

I am pretty three knives, pay attention to my personal original technology public number: back-end technology ramble

Let’s start with an RSS reader page that I’ve deployed:

Just pass in the URL the RSS feed address you want resolved, such as XXXX/RSS? Rssurl=blog.csdn.net/qqxx6661/rs… , you can parse the RSS and render it the way you want your blog to look.

The entire implementation requires only four lines of code, except for the HTML template.

Serverless concept

How does Serverless work? Here’s a quick explanation:

Tencent Cloud function is Serverless execution environment provided by Tencent Cloud. You simply write a simple, single-purpose cloud function to associate it with events generated by your Tencent cloud infrastructure and other cloud services.

Of course, Serverless does not mean that there is no server, but means that when you use Serverless, you do not need to care about the underlying resources, and do not need to log in to the server and optimize the server, just focus on the most core code fragments, you can skip the complex and tedious basic work. The core code snippet is triggered entirely by events or requests, and the platform automatically adjusts service resources in parallel to the request. Serverless has almost unlimited capacity expansion. When idle, no resources are running. Code running stateless, can easily achieve rapid iteration, rapid deployment.

Its general execution process is shown as follows:

Therefore, Serverless is essentially a cloud service to help you integrate cloud resources, you only need to write the most core code, such as how to process and return the corresponding data when a request comes. Everything else related to server deployment is left to the cloud service providers. The core benefit of this is to save a lot of resources, only when your website is visited, the price of resource consumption will be calculated, greatly reducing the cost.

Maybe you just want to set up a blog, before may need to buy a year of server, at least a few hundred yuan a year. Under Serverless, if your blog is not heavily visited, you can spend as little as $10 a year.

Deploy a website in 3 minutes

We open the Serverless create function service page:

Console.cloud.tencent.com/scf/list-cr…

Select Python3 Web function template:

Then I can set up some basic information, so I didn’t change anything here, I just hit it.

After about 30 seconds, a Serverless service is created.

Next, we are redirected to the code editing page. Since Python3 Web development was selected in the above options, the code defaults to a basic Flask framework template. What is a Flask? Python is a Web development framework for Python that, like SpringBoot in Java, makes it easy to develop Web services. The official document: flask.palletsprojects.com/en/2.0.x/)

The template code already has the basic return value of the path (“/”), so let’s change it a few words and click the deploy button in the lower left corner. After a dozen seconds of deployment, click test and you’ll see the Body returned, as shown below. When you visit the page, the same result is returned.

A most basic Web server is OK, do not need to buy domain name and HTTPS certificate, do not need SSH login server, do not need to manually compile code, 🐂🍺.

Develop an online RSS reading site in 10 minutes

So that’s a little bit of a test, and then a little bit more complicated.

** I’ve always felt that RSS reading is an outdated way of reading with a spirit that lives on. ** For example, the wechat subscription number can be said to be a kind of RSS reading in essence. You can customize your reading content by following the subscription and getting updates of articles.

Therefore, I want to make an RSS parser, which can render all the articles in the RSS link and display them on the web page by passing in the URL of RSS (many websites still have the URL, such as CSDN and Ruan Yifeng’s blog, etc.). Behind, you can also deeply modify the display of the page, to make a wechat subscription number web version, is not impossible, ha ha ha.

OK, all the bells and whistles, let’s start with the simplest thing we can do, rendering RSS links.

We use the official Flask template, which has a relatively complete Flask environment and is easy to develop.

We first need a framework for RSS parsing. In Python, there is a FeedParser framework for parsing RSS urls.

Run pip3 install feedParser to install feedParser.

Next we add code to app.py:

import feedparser

@app.route('/rss')
def rss():
    feed = feedparser.parse(request.args.get('rssurl'))
    return render_template('rss.html', entries=feed.entries)
Copy the code

Here, I do a wave of local debugging and look at the feed parameter and see what I get:

As you can see, the parsed RSS link is parsed by the FeedParser framework into an array, with each entry containing an article title, author, link, etc.

I’ll add an RSS/HTML file to the templates folder where I’ll write my slightly pretfied HTML and loop each post into the HTML, using flask’s jinja2 rendering template:

< HTML > <head> <title>RSS reading blog </title> <link Href = "https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel = "stylesheet" > < / head > < body > < script SRC = "https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/js/bootstrap.min.js" > < / script > < script SRC = "https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.slim.min.js" > < / script > < div class = "container - fluid" > < div class="row-fluid"> <div class="span12"> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div Class ="container-fluid"> <a class="navbar-brand" href="#">RSS </a> data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav me-auto mb-2 mb-lg-0"> <li Class ="nav-item"> <a class="nav-link active" aria-current="page" href="#"> home </a> </li> </ul> <form class="d-flex"> <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"> <button class="btn btn-outline-success" type="submit">Search</button> </form> </div> </div> </nav> <div class="accordion" id="accordionExample"> {% for entry in entries %} <div class="accordion-item"> <h2 class="accordion-header" id="heading{{ loop.index }}"> <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse{{ loop.index }}" aria-expanded="false" aria-controls="collapse{{ loop.index }}"> {{ entry.title }} | {{ entry.published }} </button> </h2> <div id="collapse{{ loop.index }}" class="accordion-collapse collapse" aria-labelledby="heading{{ loop.index }}" data-bs-parent="#accordionExample"> <div class="accordion-body"> {{ entry.summary | safe }} </div> </div> </div> {% endfor %} </div> </div> </div> </div> </body> </html>Copy the code

After modifying the two files, click deploy and visit the domain name assigned to us by Tencent Cloud:

Service-ehshqmzv-1252138314.cd.apigw.tencentcs.com/release/rss…

As you can see, the RSS stream of my CSDN blog has been perfectly resolved and can be opened one by one. See the GIF at the top of the article.

Analysis of advantages and disadvantages of Web Function

It can be seen that Serverless development of a website and traditional website development is very different, it skimmed the traditional development of those jumbled but not often to modify the configuration and process, so that developers focus on the development of business logic. But is this approach really perfect? I thought about its strengths and weaknesses.

The most obvious advantage of ** is that it simplifies the development process and saves a lot of boring deployment work. ** However, its simplification comes at a cost, sacrificing a lot of flexibility and customizability. Simplification works only if the cloud service providers do these things, and do them well. If your site requires a lot of complex logic and needs to optimize gateway configuration, there are a lot of things you can’t do with Serverless, at least with the currently available Serverless.

The drawbacks mentioned above will actually bring a big problem, namely sunk cost. When you spend a lot of time on Serverless, but find some small requirements or customization, you can’t achieve it. At this time, should you go to the documents and ask for work orders, or choose to buy a virtual machine and manually redeploy by yourself?

Of course, this is from a developer’s perspective.

As an average consumer, you probably only need to deploy a static website to host a blog, or to promote your company and products. Then Serverlss is most likely to meet the requirements.

In addition to the main contradiction above, another point I would like to make is that the debugging capabilities of the online code editing page are a little too weak right now.

In the original Python3 Web template, the online dependency libraries seemed to be missing the new versions of FeedParser and Flask, causing me to debug locally the code that worked on Serverless with various failures, but error messages were hard to find. As a result, I had to manually open the flask service in the VS Code terminal, and then go to the curl request to see the error message.

Sure, I may have taken the wrong path, but on the page, it’s hard to see where the Debug window is.

There’s a lot more that can be done in terms of user experience.

conclusion

Before you know it, another 2500 word article and a whole weekend gone.

The concept of Serverless has been put forward for several years, and its product form always feels to be in the exploratory stage. Whether its user group is developers or ordinary consumers, in fact, it is still affected by the product form.

However, Serverless has proven to be a cost savings, and I hope to save a lot of money by deploying my blog and other services to Serverless once my cloud server expires. Cost alone is worth keeping an eye on Serverless.

If this article is helpful to you, please share it with your boss. Your support and encouragement is the motivation for my continuous progress

Pay attention to my

I am an Internet front – line back-end development engineer.

Usually focus on back-end development, data security, welcome to exchange.

  • Wechat official account: A ramble on back-end technology
  • Making:@qqxx6661
  • CSDN: @Pretty three knives
  • Zhihu: @ Ramble on back-end technology
  • Nuggets: @ pretty three knife knife
  • Tencent Cloud + community: @ Back-end technology ramble
  • Blog Garden: @ Back-end Technology Ramblings
  • BiliBili: @Pretty three knives

Personal public account: Back-end technology ramble