The following examples show SQL query statements you can use to search for resources in Cloud Config.
-
Example 1: Find all Elastic Compute Service (ECS) instances tagged
business:onlinein the China (Shanghai) region.This query filters by resource type, region, and tag value to return the resource ID and name of each matching instance.
SELECT ResourceId, ResourceName WHERE ResourceType='ACS::ECS::Instance' AND RegionId='cn-shanghai' AND Tags.Kvpair='business:online'NoteTags are in the format of
Key:Value. -
Example 2: Count all ECS instances that have the
producttag and 1 GB of memory.This query combines a tag key filter with a memory filter to count matching instances.
SELECT COUNT(1) WHERE ResourceType='ACS::ECS::Instance' AND Memory=1024 AND Tags.Key='product' -
Example 3: Find all ECS instances created after
2021-01-01 00:00:00.This query returns the resource ID and name of each ECS instance created after the specified timestamp.
SELECT ResourceId, ResourceName WHERE ResourceType = 'ACS::ECS::Instance' AND ResourceCreationTime > '2021-01-01 00:00:00' -
Example 4: Find the elastic network interface (ENI) of an ECS instance by its private IPv4 address
198.168.XX.XX.This query returns all fields for the network interface whose private IP address matches the specified value.
SELECT * WHERE ResourceType = 'ACS::ECS::NetworkInterface' AND PrivateIpAddress = '198.168.XX.XX' -
Example 5: Count resources by resource type.
This query groups all resources by type and returns the count of each, sorted in descending order.
SELECT ResourceType, COUNT(1) GROUP BY ResourceType ORDER BY COUNT(1) DESC