Develop Function Compute with a Web Page Snipping Service

By Yi Xian

This tutorial discusses how you can develop Function Compute with a web page snipping service. But before we get down into it, let’s first take a look at several important concepts mentioned in this article.

Background Information

First, there’s Alibaba Cloud’s Function Compute, which is an event-driven service that allows users to write and upload code without having to manage server health or consider some other factors. Function Compute prepares and auto scales to the appropriate amount of computing resources necessary to run user code. The user only pays for the resources required to run their code.

Next, there’s Fun, which is a deployment tool for serverless applications. It helps you manage resources, such as Function Compute, API Gateway, and Log Service. You can use Fun to develop, build, and deploy resources by describing specified resources in the file.

And there’s also fun install, which is a sub-command of the Fun tool for installing pip and apt dependencies. It provides two forms, command line interface and description file.

Note: The techniques described in this article are applicable to Fun 2.9.3 or later.

Dependent tools

This tutorial discusses how to develop the web page snipping service. The project outlined in this tutorial is developed on macOS but it also involves platform-independent tools, which are compatible with Linux and Windows. Before proceeding to this example, make sure that Docker, Fun, and Fcli are correctly installed, updated to the latest version and properly configured. You can download, update, and configure these tools with the instructions and resources on the pages linked here.

Fun and Fcli depend on Docker to simulate the local environment. MacOS users can use homebrew to install these tools:

Windows and Linux users can refer to Installation to learn how to install these tools. After the installation, don’t forget to first run to initialize the configuration.

Develop the Web Page Snipping Service

You can use the subcommand to easily initialize a local project using this template.

The preceding code will prompt you to:

  1. Enter an OSS Bucket. Note that this OSS Bucket must be globally unique. The chrome-headless in the preceding sample is already in use. You need to enter a new name or use a Bucket that has been created (make sure that the region of the created Bucket is consistent).
  2. Select an OSS region. Make sure that the region is the same as the region where Function Compute is deployed.
  3. Enter a key with write access to OSS.

Next, you’ll want to install dependencies using the command:

The command runs the tasks in the :

  1. Install the file that puppeteer depends on.
  2. Upload the binary file that puppeteer depends on to OSS.

Install the dependency.

To deploy the project, use the command:

Last, run the project.

Open the preceding link returned and you can see that the screenshot taken is a full-screen scrolling picture. Only a part of the screenshot is provided due to the space limit:

Image for post
Image for post

To change a URL, you can use the following command format:

Then, to debug your code locally, you can use the following command:

Original Source

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store