New User FREE Learning Path

Challenge ACA Cloud Computing for Free

Step 1: Claim the New User Benefit

Step 2: Redeem FREE Clouders to learn

Step 3: Get a FREE ACA Certification Exam

Operate and Manage a Cloud Server

Free

Use DataService Studio Of DataWorks To Publish APIs

1. Experiment

1.1 Knowledge points

This experiment uses DataService Studio of Alibaba Cloud DataWorks. It demonstrates how to publish APIs by using DataService Studio of DataWorks. The DataService Studio of DataWorks aims at building a centralized data service bus to help enterprises manage all internal and external APIs. You can quickly create APIs in DataService Studio based on data tables or register existing APIs for centralized management and publishing.

1.2 Experiment process

  • Prepare an RDS environment.
  • Create a DataWorks environment.
  • Use DataService Studio to create APIs.

1.3 Cloud resources required

  • ECS
  • RDS
  • Dataworks
  • Api Gateway

1.4 Prerequisites

  • If you’re using your own Alibaba Cloud account instead of the account provided by this lab to operate the experiment, please note that you’ll need to choose the same Ubuntu 16.04 operating system for your ECS in order to run the experiment smoothly.
  • Before starting the experiment, please confirm that the previous experiment has been closed normally and exited.

2. Start the experiment environment

Click Start Lab in the upper right corner of the page to start the experiment.

image desc.

After the experiment environment is successfully started, the system has deployed resources required by this experiment in the background, including the ECS instance, RDS instance, Server Load Balancer instance, and OSS bucket. An account consisting of the username and password for logging on to the Web console of Alibaba Cloud is also provided.

image desc

After the experiment environment is started and related resources are properly deployed, the experiment starts a countdown. You have two hours to perform experimental operations. After the countdown ends, the experiment stops, and related resources are released. During the experiment, pay attention to the remaining time and arrange your time wisely. Next, use the username and password provided by the system to log on to the Web console of Alibaba Cloud and view related resources:

openCole

Go to the logon page of Alibaba Cloud console.

image desc

Fill in the RAM user name and click Next.

image desc

Fill in the RAM user password and click Log on.

image desc

After you successfully log on to the console, the following page is displayed.

image desc

3. Prepare the RDS environment

3.1 Configure the whitelist

Choose Products and Services > ApsaraDB for RDS to log on to the ApsaraDB for RDS console.

image desc

You can see that an RDS instance is being created. Wait a few minutes until the status changes to Running.

image desc

Click Manage to go to the details page.

image desc

Click Configure Whitelist to configure a whitelist.

image desc

Click Modify.

image desc

Edit the whitelist, as shown in the following figure. Then, click OK.

image desc

3.2 Create an administrator account

Click Create Account, as shown in the following figure.

image desc

Configure the account and password, and then click OK, as shown in the following figure.

image desc

The account is created.

image desc

3.3 Apply for a public endpoint

Click Apply for Public Endpoint, as shown in the following figure.

image desc

Click OK.

image desc

The public endpoint is created.

image desc

3.4 Import data

Click Elastic Compute Service, as shown in the following figure.

image desc

We can see one running ECS instance in the US West 1 region. Click it to go to the ECS console as shown in the following figure.

image desc

Copy this ECS instance’s Internet IP address and remotely log on to this ECS (Ubuntu system) instance. For more information about remote logon, see [How to Remotely Log in to Alibaba Cloud’s ECS Server] (https://labex.io/questions/150).

image desc

The default account name and password of the ECS instance:

Account name: root

Password: nkYHG890..

After you log on to the ECS instance, run the following command to install the MySQL client:

apt update && apt -y install git mysql-client

image desc

Run the following command to clone a Github repository of a MySQL project:

git clone https://github.com/datacharmer/test_db.git

image desc

Run the following command to import data to your RDS database. Note: Replace YOUR-RDS-PRVIATE-ADDRESS with the private IP address of your RDS instance.

cd test_db

mysql -ulabex -pAliyun-test -hYOUR-RDS-PRVIATE-ADDRESS < employees.sql

image desc

As shown in the following figure, you can obtain the internal endpoint of the RDS instance.

image desc

The data is imported.

4. Create a DataWorks environment

4.1 Create a DataWorks workspace

In the Alibaba Cloud console, choose DataWorks.

image desc

On the Workspace List page, choose US West 1 and click Create Workspace.

image desc

Set the project name, select Standard Mode for Mode, and click Next.

image desc

Select the MaxCompute engine and click Next.

image desc

Set the Instance Display Name, and click Create Workspace.

image desc

The creation is complete.

image desc

After a while, the status will be displayed as Normal, and the creation is successful.

image desc

4.2 Add a MySQL data source

Go back to the DataWorks console and click Data Integration.

image desc

Click Data Sources.

image desc

Click Add data source.

image desc

Click MySQL.

image desc

Select Connection string mode. Note: Replace YOUR-RDS-PUBLIC-ADDRESS with the public endpoint of your RDS instance. After the test connection is successful, click Complete.

Enter the value of JDBC URL in the following format.

jdbc:mysql://YOUR-RDS-PUBLIC-ADDRESS:3306/employees

image desc

The value of YOUR-RDS-PUBLIC-ADDRESS is the public endpoint you applied for in Section 3.3.

The data source is added.

image desc

5. Use DataService Studio to create APIs

5.1 Create an API group

Refer to the figure below and go to ApiGateway.

image desc

Click Create Group.

image desc

image desc

Go back to the DataWorks console and click DataService Studio.

image desc

Create an Business process, as shown in the following figure.

image desc

image desc

Create success.

image desc

5.2 Create an API in wizard mode

Create an API in the selected API group, as shown in the following figure.

image desc

Set API Name, API Path, and Description, and then click OK, as shown in the following figure.

image desc

The API is created.

Edit the API content, as shown in the following figure.

Select the “salaries” table in the database, set the “emp_no” field as the request field, and then set the other three fields as the response fields.

Click the Save icon in the upper-left corner.

image desc

After you save the configuration, click Test in the upper-right corner.

image desc

Set the request parameter “emp_no” to 111035, and click Test.

image desc

The first API is created. After you publish the API, you can directly use it or use an application to call it.

5.3 Create an API in script mode

It is easy and intuitive to edit an API created in wizard mode, but you cannot perform multi-table queries.

If you need to perform multi-table queries, you must create APIs in script mode.

Choose Script Mode, as shown in the following figure.

image desc

Set API Name, API Path, and Description, and then click OK, as shown in the following figure.

image desc

As shown in the following figure, select a data source, copy and paste the following SQL statements to the Edit query SQL text box, and then click the Save icon in the upper-left corner.

select d.emp_no, e.first_name, e.last_name, d.from_date, d.to_date from dept_manager d, employees e where d.dept_no = (select dept_no from departments where dept_name = '${dept_name}') and e.emp_no = d.emp_no

image desc

Click Test.

image desc

Set the request parameter “dept_name” to Marketing, and click Test.

image desc

5.4 Publish APIs

Publish the API “query1”, as shown in the following figure.

image desc

Publish the API “query2”, as shown in the following figure.

image desc

Go to the API Gateway console of Alibaba Cloud.

image desc

Select the US (Silicon Valley) region.

The two APIs are published, as shown in the following figure.

image desc

An application with the same name as the DataWorks project is automatically created.

image desc

5.5 Call APIs

Use a call to API query2 an example.

Click Manage.

image desc

Click Custom Sample Code. You can see different sample code for calling the current API in different languages.

Copy the Python demo code.

image desc

Go back to the command line interface (CLI) of the ECS instance. Run vim call.py to create a python script file, paste the copied content to the file, and then modify the three parameters in the code, as shown in the following figure.

image desc

The value of parameter 1 is the address of the current API group.

image desc

image desc

The value of parameter 2 is the AppCode of the API.

image desc

image desc

Run the following command to execute the script file.

python call.py

image desc

Finally, format the returned json string.

image desc

Reminder:
Log out your Alibaba RAM user account before you click stop to leave this lab. Otherwise you’ll encounter some issues when opening a new lab session in the same browser:

image descimage desc

6. Experiment summary

This experiment demonstrates how to publish APIs by using DataService Studio of DataWorks. DataService Studio is connected to API Gateway and supports one-click publishing of API services to API Gateway. DataService Studio works together with API Gateway to provide a secure, stable, low-cost, and easy-to-use data sharing service. DataService Studio adopts the serverless architecture. You only need to focus on the logic of API queries instead of the infrastructures, such as the operation environment. DataService Studio provides computing resources and supports auto scaling without any operation and maintenance (O&M) costs.