By Du Wan (Yixian)
First, let's take a quick look at several key concepts mentioned in this article:
template.yml
file. For more information about Fun, see here.Note: The operations in this article are applicable to Fun version 3.0.0-beta.7 and other later versions.
This project development is based on MacOS. However, the tools involved are platform-independent and also applicable to the Linux and Windows operating systems. Before proceeding with the example, make sure that the following tools are correctly installed, updated to the latest version, and properly configured.
Fun is based on Docker to simulate the local environment.
MacOS users may use homebrew to install these tools:
brew cask install docker
brew tap vangie/formula
brew install fun
Windows and Linux users may refer this article to install these tools. After the installation, first run the fun config
command to initialize the configuration.
Note: Make sure to use Fun version 3.0.0-beta.7 or any later version.
$ fun --version
3.0.0-beta.7
Run the fun init
command to locally initialize a project according to the specified template.
fun init vangie/ghostscript-example
Execute the commands shown in the following snippet to install dependencies.
$ fun install
Installing recursively on fun.yml
skip pulling image aliyunfc/runtime-python3.6:build-1.6.1...
Task => workaround for update-gsfontmap
=> bash -c 'mkdir -p /code/.fun/root/etc/ghostscript/cidfmap.d/ && mkdir -p /code/.fun/root/etc/ghostscript/fontmap.d/ && mkdir -p /etc/ghostscript/ && mkdir -p /var/lib/ghostscript/ && mkdir -p /code/.fun/root/var/lib/ghostscript/fonts && ln -s /code/.fun/root/etc/ghostscript/cidfmap.d /etc/ghostscript/ && ln -s /code/.fun/root/etc/ghostscript/fontmap.d /etc/ghostscript/ && ln -s /code/.fun/root/var/lib/ghostscript/fonts /var/lib/ghostscript/'
Task => [UNNAMED]
=> apt-get update (if need)
=> apt-get install -y -d -o=dir::cache=/code/.fun/tmp/install ghostscript --reinstall
=> bash -c
for f in $(ls /code/.fun/tmp/install/archives/*.deb); do
dpkg -x $f /code/.fun/root;
mkdir -p /code/.fun/tmp/install/deb-control/${f%.*};
dpkg -e $f /code/.fun/tmp/install/deb-control/${f%.*};
if [ -f "/code/.fun/tmp/install/deb-control/${f%.*}/postinst" ]; then
FUN_INSTALL_LOCAL=true /code/.fun/tmp/install/deb-control/${f%.*}/postinst configure;
fi;
done;
Creating config file /etc/papersize with new version
=> bash -c 'rm -rf /code/.fun/tmp/install/archives'
Run the following commands to call the function locally.
$ fun local invoke pdf2jpg
using template: template.yml
skip pulling image aliyunfc/runtime-nodejs10:1.6.1...
FC Invoke Start RequestId: 21d9c646-1db4-403c-b018-cd4246e193d3
load code for handler:index.handler
2019-09-18T09:45:38.400Z 21d9c646-1db4-403c-b018-cd4246e193d3 [verbose] stdout =================== START
2019-09-18T09:45:38.400Z 21d9c646-1db4-403c-b018-cd4246e193d3 [verbose] GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
2019-09-18T09:45:38.401Z 21d9c646-1db4-403c-b018-cd4246e193d3 [verbose] stdout =================== END
FC Invoke End RequestId: 21d9c646-1db4-403c-b018-cd4246e193d3
convert success.
JPG file save to /tmp/test.jpg
2019-09-18T09:45:38.416Z 21d9c646-1db4-403c-b018-cd4246e193d3 [error](node:21) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
RequestId: 21d9c646-1db4-403c-b018-cd4246e193d3 Billed Duration: 2132 ms Memory Size: 1998 MB Max Memory Used: 78 MB
View the converted fun/tmp/invoke/ghostscript/%2jpg/test.jpg
file.
Execute the commands below to deploy the function.
$ fun deploy
using template: template.yml
using region: cn-shanghai
using accountId: ***********4733
using accessKeyId: ***********EUz3
using timeout: 60
Waiting for service ghostscript to be deployed...
Waiting for function pdf2jpg to be deployed...
Waiting for packaging function pdf2jpg code...
The function pdf2jpg has been packaged. A total of 1054 files files were compressed and the final size was 23.44 MB
function pdf2jpg deploy success
service ghostscript deploy success
Finally, run the commands shown below to call the function.
$ fun invoke pdf2jpg
fun invoke pdf2jpg
using template: template.yml
========= FC invoke Logs begin =========
FC Invoke Start RequestId: 1411066b-1ad0-4750-922d-2350652ca5a6
load code for handler:index.handler
2019-09-18T09:52:39.802Z 1411066b-1ad0-4750-922d-2350652ca5a6 [verbose] stdout =================== START
2019-09-18T09:52:39.802Z 1411066b-1ad0-4750-922d-2350652ca5a6 [verbose] GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
2019-09-18T09:52:39.802Z 1411066b-1ad0-4750-922d-2350652ca5a6 [verbose] stdout =================== END
FC Invoke End RequestId: 1411066b-1ad0-4750-922d-2350652ca5a6
Duration: 513.34 ms, Billed Duration: 600 ms, Memory Size: 128 MB, Max Memory Used: 56.49 MB
========= FC invoke Logs end =========
FC Invoke Result:
convert success.
JPG file save to /tmp/test.jpg
How to Develop Function Compute - Using LibreOffice to Convert Word Files to PDF Files
99 posts | 7 followers
FollowAlibaba Cloud Serverless - April 7, 2020
Alibaba Cloud Serverless - April 7, 2020
francisndungu - December 12, 2018
Alibaba Cloud Serverless - March 19, 2019
Alibaba Clouder - January 30, 2019
Alibaba Clouder - January 18, 2021
99 posts | 7 followers
FollowAlibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.
Learn MoreVisualization, O&M-free orchestration, and Coordination of Stateful Application Scenarios
Learn MoreServerless Application Engine (SAE) is the world's first application-oriented serverless PaaS, providing a cost-effective and highly efficient one-stop application hosting solution.
Learn MoreAlibaba Cloud (in partnership with Whale Cloud) helps telcos build an all-in-one telecommunication and digital lifestyle platform based on DingTalk.
Learn MoreMore Posts by Alibaba Cloud Serverless