This topic describes how to use Logic Composer to regularly export bills in an Alibaba Cloud account by calling the QueryBill operation of Alibaba Cloud to an RDS instance. You can export bills in multiple accounts.
Architecture
This architecture shows that you can use Logic Composer to call the billing API, obtain bill data, and write data to an RDS instance by using the MySQL connector provided by Logic Composer. You can analyze and display bills based on the data in the RDS database. You can use triggers of Logic Composer to automatically export the bill data to the RDS instance on a daily basis.
The following figure shows the overall architecture:
Preparations
Create an RDS instance. For more information, see Create an ApsaraDB RDS for MySQL instance.
When the instance is running, prepare the following information:
Obtain the public endpoint and port number of the database of the RDS instance. For more information, see View and change the internal and public endpoints and port numbers of an ApsaraDB RDS for MySQL instance and Apply for or release a public endpoint.
Create a database, create an account on the database, set the password, and grant the read and write permissions to this account. For more information, see Create an account on an ApsaraDB RDS for MySQL instance.
Configure a database whitelist so that Logic Composer can access the database. You can submit a ticket to obtain the specific whitelist information. For more information, see Configure an IP address whitelist for an ApsaraDB RDS for MySQL instance.
Create a workflow
Log on to the Logic Composer console by using your Alibaba Cloud account. In the left-side navigation pane, click Workflows.
Click Create Workflow. In the dialog box that appears, set the Workflow Name and Resource Group parameters and click OK. In the dialog box that appears, select Import Official Template.
In the dialog box that appears, select Regularly export InstanceBill data to RDS. A workflow is created.
Configure the workflow
After the workflow is created, the Graphic View tab is displayed. You need to configure the database connector and grant Logic Composer permissions to call the billing API. After you grant permissions, Logic Composer can call the billing API and write data into the RDS instance. Logic Composer analyzes the template you import and lists all the operations on which you must grant permissions.
In the row of the database connector, click Create. In the sidebar that appears, enter the public endpoint, port number, database name, username, and password of the RDS instance.
In the row of Alibaba Cloud billing API operation, click Authorize. The Grant Role sidebar appears. Select AliyunBSSFullAccess
.
After you complete all authorization operations, each item in the authorization list turns green. Click Continue to enter the Graphical View page.
Configure parameters
On the canvas page, you can configure running variables. For example, the SetTotalMonths node indicates the number of months in which data is imported. You can modify the settings based on your needs. Take another example. The template you import starts to import data on the first day of each month. You can modify the trigger settings to start data import at 04:00 every day. You only need to expand the Recurrence task node on the canvas and modify the related configurations.
Run a workflow
After you configure the parameters, click Save and click Run. Wait until the workflow is complete.
If the amount of data is large, it takes some time to import the data. This is mainly determined by the amount of bill data in the account and the duration of writing data to the database.
Query execution results of the workflow
On the Execution Log tab, you can view the running records. If the status is Successful, the import is complete.
If the status is Failed, click the View button to check the details, such as whether the configurations of the database whitelist are valid or whether the API call fails. If an error occurs, you can adjust the parameters and run the workflow again. The template is also processed accordingly and the data is not imported repeatedly.