Docs
Plugins
Sources
Alibaba Cloud
Overview

Alibaba Cloud Source Plugin

Latest: v2.1.1

The Alibaba Cloud source plugin for CloudQuery extracts configuration from the Alibaba Cloud (阿里云) API (opens in a new tab) and loads it into any supported CloudQuery destination (e.g. PostgreSQL, BigQuery, Snowflake, and more).

Configuration

The following configuration syncs from Alibaba Cloud to a Postgres destination. The (top level) source spec section is described in the Source Spec Reference. The config for the postgresql destination is not shown here. See our Quickstart if you need help setting up the destination.

kind: source
spec:
  name: "alicloud"
  path: "cloudquery/alicloud"
  version: "v2.1.1"
  tables: ["*"]
  destinations: ["postgresql"]
  spec:
    accounts:
      - name: my_account
        regions:
        - cn-hangzhou
        - cn-beijing
        - eu-west-1
        - us-west-1
        # ...
        access_key: ${ALICLOUD_ACCESS_KEY}
        secret_key: ${ALICLOUD_SECRET_KEY}
  • accounts (array[object], required):

    A list of accounts to sync. Every account must have a unique name, and must specify at least one region. The access_key and secret_key are required and can be specified as environment variables, as shown in the example above.

    • name (string, required): A unique name for the account.
    • regions (array[string], required): A list of regions to sync. For example, ["cn-hangzhou", "cn-beijing"].
    • access_key (string, required): A valid access key for the account
    • secret_key (string, required): A valid secret key for the account, corresponding to the access key
  • bill_history_months (int, optional):

    The number of months of billing history to fetch for the alicloud_bss_bill and alicloud_bss_bill_overview tables. Defaults to 12.

See the Alibaba documentation (opens in a new tab) for how to obtain an AccessKey pair.

Authentication

Authentication is done via access keys. See Obtain an AccessKey pair (opens in a new tab) for more information.

It is highly recommended that you use environment variable expansion to store your access key pair. For example, you can set the following environment variables:

  • ALICLOUD_ACCESS_KEY - The access key ID.
  • ALICLOUD_SECRET_KEY - The access key secret.

And then use them in the configuration as follows:

access_key: ${ALICLOUD_ACCESS_KEY}
secret_key: ${ALICLOUD_SECRET_KEY}

Example Queries

Find all ECS instances in a region

select 
  instance_id, 
  os_name, 
  region_id, 
  start_time, 
  tags 
from 
  alicloud_ecs_instances 
where 
  region_id = 'eu-west-1';
+------------------------+--------------------------------------+-----------+-------------------+---------------+
| instance_id            | os_name                              | region_id | start_time        | tags          |
|------------------------+--------------------------------------+-----------+-------------------+---------------|
| i-xxxxxxxxxxxxxxxxxxxx | Alibaba Cloud Linux  3.2104 LTS 64位 | eu-west-1 | 2023-01-17T14:40Z | {"Tag": null} |
+------------------------+--------------------------------------+-----------+-------------------+---------------+

Query past bills

select 
  product_name, 
  item, 
  pip_code, 
  currency, 
  adjust_amount 
from 
  alicloud_bss_bill_overview;
+------------------------+----------------+----------+----------+---------------+
| product_name           | item           | pip_code | currency | adjust_amount |
|------------------------+----------------+----------+----------+---------------|
| Object Storage Service | PayAsYouGoBill | oss      | USD      | 0.0           |
+------------------------+----------------+----------+----------+---------------+

Query bucket stats

select 
  account_id, 
  bucket_name, 
  object_count, 
  storage 
from 
  alicloud_oss_bucket_stats;
+------------+-------------+--------------+---------+
| account_id | bucket_name | object_count | storage |
|------------+-------------+--------------+---------|
| test       | cq-test     | 2            | 29665   |
+------------+-------------+--------------+---------+