Welcome to FaaS

https://img.shields.io/badge/FaaS-v0.3.0-orange.svghttps://img.shields.io/badge/license-MIT-blue.svg

FaaS

Our project is also named FaaS, which is a project based on Tencent Serverless Cloud Function(SCF) to provide users fast images processing services. We use their SCF service to develop our cloud function, use their Cloud Object Storage(COS) to store figures and use API Gateway to custom our APIs to release to users.

Introduction

Concepts

Note

This part will roughly introduce some concepts related to FaaS since they will help you better understand this project and the motivations behind it.

Serverless Computing

Cloud computing is popularized since Amazon released its EC2 in 2006. The past few years have seen the rapid developments of cloud computing, the models of cloud computing have changed both in its architectures and its orientation. The most recent hot topics raised from this field is widely-known Serverless Computing. Such a name makes this model a little ambiguous for the general public and the latest architecture FaaS is also little known to the public. However, more and more people are using these servers either consciously or unconsciously. They break through the wall of local computing and support more powerful online services such as online language translation, navigation, and so on.

Function as a Service

Function as a service (FaaS) is a category of cloud computing services that provides a platform allowing customers to develop, run, and manage application functionalities without the complexity of building and maintaining the infrastructure typically associated with developing and launching an app. Building an application following this model is one way of achieving a “serverless” architecture, and is typically used when building microservices applications.

API Gateway

API Gateway typically works as a set of modules and filters which treat the traffic as it flows through it at high speed and you can typically enable those modules / filters you need and control their parameters. There are obviously quite a few different ways to actually do the implementation + various vendors and open source systems to choose from.(Stackoverflow)

Advantages

  • Lower cost: save infrastructure costs, personnel cost, and development costs
  • Strong scalability
  • Simplied management
  • High resource utilization

Motivation

Our project is motivated by Stone with his great idea. The original idea is to balance a load of servers using FaaS, for some interesting things sharing through WeChat Moments with some short period computing needed.

The big problem of such case is not the computation of a single request but a large number of requests happened concurrently.

APIs

Overview

Image Processing includes 3 steps, which are uploading, processing and downloading (or showing).

Uploading

upload image to Tencent COS.

Authorization

Send a GET query for getting a temp secret key to your authorization server.

Parameter Type Value
method str “POST”,which is the upload method.
pathname str “/”, which is the path in COS.
key str File name
File uploading

Using Tencent COS JavaScript SDK to send a POST query for uploading file to Tencent COS server directly. The file size is limited to 20M.

Parameter Value
Authoriza Signature generated by previous request.
x-cos-security-token The sessionToken of the temp secret key.

Processing

Fetching

Send a POST query with a json for processing uploaded file.

  • ‘Content-Type’: ‘application/json’

Field Description

Parameter Type Value
file_name str File name
op int Operation number (0 - 7)
op_par dict Operation parameter
Rotation

Field Description

Parameter Type Value
angle int The angle to rotate. Counter clock
QR code

Field Description

Parameter Type Value
content str String store in QR code.
position int or dict When fixed = 0, the position of QR Code has 5 choices: 1 for Upper Left, 2 for Upper Right, 3 for Center, 4 for Bottom Left, 5 for Bottom Right (default = 5). When fixed = 1, the position is defined by the pixel point in the original graph (width, height).
fixed int 0 for using relative position, 1 for using fixed pixel position. (default = 0)
Round

Field Description

Parameter Type Value
radius float If fixed = 0, radius represent in ratio; If fixed = 1, radius represent in pixel.
fixed int 0 for using relative position, 1 for using fixed pixel position. (default = 0)
Thumbnail

Field Description

Parameter Type Value
height int Thumbnail height
width int Thumbnail width
Watermark with text

Field Description

Parameter Type Value
content str The water mark text
font_name str The name of font style
size_ratio float The size of water mark based on input figure
rotate_angle int The rotate angle for text. Counter clock
clear_ratio float The contrast between the watermark and the background
position int or dict When fixed = 0, the position of QR Code has 5 choices: 1 for Upper Left, 2 for Upper Right, 3 for Center, 4 for Bottom Left, 5 for Bottom Right (default = 5). When fixed = 1, the position is defined by the pixel point in the original graph (width, height).
fixed int 0 for using relative position, 1 for using fixed pixel position. (default = 0)
Watermark with image

Field Description

Parameter Type Value
patch str The path for water mark image
clear_ratio float The contrast between the watermark and the background
position int or dict When fixed = 0, the position of QR Code has 5 choices: 1 for Upper Left, 2 for Upper Right, 3 for Center, 4 for Bottom Left, 5 for Bottom Right (default = 5). When fixed = 1, the position is defined by the pixel point in the original graph (width, height).
fixed int 0 for using relative position, 1 for using fixed pixel position. (default = 0)
Slicing

Field Description

Parameter Type Value
num int number of slices
direction int 1 for slice vertical, 0 for slice horizontal
Image Converter

Field Description

Parameter Type Value
postfix str Image postfix

Processing Response

Previous query response a json.

Field Description

Parameter Type Value
data dict All processed files’ name
file_cnt int File count in the data field

Downloading

Previous query will return a download file name. Then, the processed image can be downloaded from Tencent COS.

Architecture

Description

Our project is based on Tencent Cloud. Three products are used in our project.

  • SCF: provide a runtime environmemt.
  • COS: store staff.
  • API Gateway: expose services to users.

Workflow

APIs is the only service expose to user, which they can directly access. API-gateway receive all external user web request and response corresponding processed data. The request will be passed to COS or SCF for further handling. COS processes the data storage task. SCF deals with image processing.

A whole image processing request contains 4 sub-queries.

  1. Get authorized secret key to upload image
    For safety reasons, the user cannot get the authorization for uploading image as the administrator. Users’ image will be checked and users will be returned an authorized signature for uploading an image to COS.
  2. Upload image with signature
    User upload image with the signature.
  3. Post parameter to image processing
    User post the image processing query to the API, which includes the parameters. A processed image path will be returned.
  4. Download processed image
    User can preview or download processed image from previous path.
_images/architecture.png

Changelog

v 0.3.0

  • Add customized parameters for all functions
  • Add new image processing functions
  • Docs published

v 0.2.0

  • Add most image processing function we planned before, but most parameters cannot be defined by users.
  • Demo website setup

v 0.1.0

  • Requirement analysis
  • Architecture setup
  • Task assignment

Todo

Scheme

Todo

  • to business productization

Functions

Todo

  • Add verification for images
  • Add API docs for return values for all functions
  • Bugfix
  • Testing

Acknowledgements

Team

Tutors

Tencent:
SUSTech:
  • Yuqun Zhang

About

Support

If you are having issues, please let us know via E-mail 510662916@qq.com.

License

The project is licensed under the MIT license.