Building a Serverless Application on Alibaba Cloud (Part 2)

Building a Serverless Application on Alibaba Cloud

From the first part we have seen that the serverless architecture can be realised using the following components:

  • Alibaba Cloud’s Object Storage Service (OSS), which will store your static content such as HTML, CSS, Javascript files and images.
  • Alibaba Cloud’s Function Compute, which will contain and execute the code for your application logic.
  • Alibaba Cloud’s ApsaraDB for MongoDB, which will act as a backend database server of your system.

Set up Object Storage Service (OSS)

Log in to the Alibaba Cloud console, you will find Object Storage Service on the left menu. If this is the first time you will be using OSS, it will ask you to activate the service. Click on the checkbox to agree with the agreement and enable the service.

Step 1: Create a bucket

Click the + icon to create a new bucket.

  • Standard: high reliability and availability for frequent access files
  • Infrequent Access (IA): long-term storage, infrequent access, lower storage price
  • Archive: long-term storage, very infrequent access, lowest storage price

Step 2: Upload files to the bucket

Creating folders and uploading files are pretty straight-forward. Just click on the buttons on the user interface.

Step 3: View the website

After you have finished uploading all files of your website to your bucket, click the Overview tab to view the address.

Map a custom domain name to an OSS bucket

Automatically, OSS assigns a domain name to your bucket in the following format:

[bucket name].[endpoint]

Set up Alibaba Cloud ApsaraDB for MongoDB

MongoDB is a popular name in the NoSQL family . MongoDB databases can be deployed on Alibaba Cloud via its ApsaraDB for MongoDB service. Users can select among 3 pricing schemes:

  • Subscription (Replica Set)
  • PAYG (Pay-As-You-Go) (Replica Set)
  • PAYG (Sharding)
  • Replication copies data across multiple servers. The same piece of data is stored in different places. ApsaraDB for MongoDB uses a 3-server replica set. Replication may help with horizontal scaling of reads.
  • Sharding distributes data across multiple machines so different machine contains different subset of data. This model allows for horizontal scaling of writes.

Step 1: Create an instance

In the Alibaba Cloud console, click on Products and you will see ApsaraDB for MongoDB under the ApsaraDB group. Alternatively, you can use the search box to filter the desired service.

Step 2: IP whitelists and Connection String

To ensure database security Alibaba Cloud automatically block all access to the database. You have to specify IP addresses in the whitelist to gain access to the target instance.

ip.png1029x146 3.02 KB

Create a Function Compute

Function Compute lets you run code without provisioning or managing servers. This service prepares computing resources for you and runs your codes on your behalf elastically and reliably. You only pay for resources actually consumed when running the codes. If your code isn’t executed, you won’t pay anything.

code.PNG630x572 23.4 KB
  • Monitoring user behavior on a website: for example, the user’s mouse click will trigger a function to record what item the user has clicked on.
  • Image processing: when users upload images to OSS buckets, a function is triggered to create a thumbnail or to add a watermark to the image.
  • Automation tool: functions can be called on a schedule to process repetitive tasks like creating backups, generating reports or performing various other routine jobs.
  • Internet of Things (IoT) platforms: an Internet-of-Things (IoT) sensor can output trigger functions to control other devices in the network.

More about Function Compute

Above we have gone over the basic steps you can use to create and set up a Function Compute to execute your application logic. Function Compute is a very powerful product, which can help provide the capabilities necessary to run and scale out your system. It automatically can handle your scalability, high availability, security, performance requirements and do so all by its own. In addition, this service also provides log query, performance monitoring, and alarms, among several other useful features.

Summary

In this tutorial, we have gone through the steps to set up a serverless application on Alibaba Cloud ecosystem. By using Object Storage Service, ApsaraDB for MongoDB and Function Compute, we have created a fully-managed event-driven compute service that allows you to run code more flexibly and reliably. No maintenance is required for this application. This model also brings you the convenience of real-time auto scaling and dynamic load balancing within milliseconds. Welcome to the new world of application development and service provision.

Original Source

--

--

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
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com