In this tutorial, you will learn how to develop Function Compute with a web page snipping service.
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.
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
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
fun.yml description file.
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.
brew cask install docker brew tap vangie/formula brew install fun brew install fcli
Windows and Linux users can refer to Installation to learn how to install these tools. After the installation, don't forget to first
fun config to initialize the configuration.
Develop the Web Page Snipping Service
fun initsubcommand to easily initialize a local project using this template.
fun init vangie/puppeteer-example Please input oss bucket to upload chrome shell? chrome-headless Please select a region? cn-hangzhou Please input oss accessKeyId for upload? xxxxxxxxxxxKbBS Please input oss accessKeySecret for upload? xxxxxxxxxxxx5ZgM
- 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).
- Select an OSS region. Make sure that the region is the same as the region where Function Compute is deployed.
- Enter a key with write access to OSS.
fun install skip pulling image aliyunfc/runtime-nodejs8:build-1.2.0... Task => [UNNAMED] => apt-get update (if need) => apt-get install -y -d -o=dir::cache=/code/.fun/tmp libnss3 => bash -c 'for f in $(ls /code/.fun/tmp/archives/*.deb); do dpkg -x $f /code/.fun/root; done;' => bash -c 'rm -rf /code/.fun/tmp/archives' Task => [UNNAMED] => bash -c 'curl -L https://github.com/muxiangqiu/puppeteer-fc-starter-kit/raw/master/chrome/headless_shell.tar.gz --output headless_shell.tar.gz' ...
fun installcommand runs the tasks in the
- Install the
.sofile that puppeteer depends on.
- Upload the
chrome headlessbinary file that puppeteer depends on to OSS.
fun deploy using region: cn-shanghai using accountId: ***********4733 using accessKeyId: ***********KbBS using timeout: 60 Waiting for service puppeteer to be deployed... Waiting for function html2png to be deployed... Waiting for packaging function html2png code... package function html2png code done function html2png deploy success service puppeteer deploy success
fcli function invoke -s puppeteer -f html2png The screenshot has been uploaded to http://chrome-headless.oss-cn-shanghai.aliyuncs.com/screenshot.png
fcli function invoke -s puppeteer -f html2png --event-str 'http://www.alibabacloud.com'
fun local invoke html2png <<<'http://www.alibaba.com'