Skip to content

Collector「AWS-EC2」Configuration Manual

Before reading this, please first read:

Before using this collector, you must install the 「Integration Core Package」and its associated third-party dependency packages

1. Configuration Structure

The configuration structure for this collector is as follows:

Field Type Required Description
regions list Required List of regions to collect data from
regions[#] str Required Region ID. For example: 'cn-north-1'
See full table in appendix

2. Configuration Example

Specify Regions

Collect instance data from Ningxia and Beijing regions

Python
1
2
3
collector_configs = {
    'regions': [ 'cn-northwest-1', 'cn-north-1' ]
}

Configure Filters (Optional)

This collector script supports user-defined filters that allow users to filter target resources by object properties. The filter function returns True or False.

  • True: The target resource needs to be collected.
  • False: The target resource does not need to be collected.

Supported object property filters:

Property Description
InstanceId Instance ID
RegionId Region ID
PlatformDetails Operating System
InstanceType Instance Type
InstanceName Instance Name

When enabling custom object collection, refer to the corresponding documentation for supported object properties.

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Example: Enable filters based on the InstanceId and RegionId properties of the object, with the following configuration format:

def filter_instance(instance, namespace='AWS/EC2'):
    '''
    Collect instances with InstanceId i-xxxxxa, i-xxxxxb
    '''
    instance_id = instance['tags'].get('InstanceId')
    if instance_id in ['i-xxxxxa', 'i-xxxxxb']:
        return True
    return False

from guance_integration__runner import Runner
import guance_aws_ec2__main as main

@DFF.API('AWS-EC2 Collection', timeout=3600, fixed_crontab='*/15 * * * *')
def run():
    Runner(main.DataCollector(account, collector_configs, filters=[filter_instance])).run()

3. Data Reporting Format

After data synchronization, the data can be viewed in the 「Infrastructure - Resource Catalog」of {{( brand_name )}}.

Example of reported data:

JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
{
  "measurement": "aws_ec2",
  "tags": {
    "name"            : "i-0d7620xxxxxxx",
    "InstanceId"      : "i-0d7620xxxxxxx",
    "InstanceType"    : "c6g.xlarge",
    "PlatformDetails" : "Linux/UNIX",
    "RegionId"        : "cn-northwest-1",
    "InstanceName"    : "test",
    "State"           : "running",
    "StateReason_Code": "Client.UserInitiatedHibernate",
    "AvailabilityZone": "cn-northwest-1",
  },
  "fields": {
    "BlockDeviceMappings": "{JSON device data}",
    "LaunchTime"         : "2021-10-26T07:00:44Z",
    "NetworkInterfaces"  : "{JSON network data}",
    "Placement"          : "{JSON availability zone data}",
    "message"            : "{JSON instance data}"
  }
}

Fields in tags and fields may change with subsequent updates

The value of tags.name is the instance ID, used as a unique identifier

fields.message, fields.NetworkInterfaces, fields.BlockDeviceMappings are JSON serialized strings

4. IAM Policy Permissions

If the user uses an IAM role method to collect resources, certain operation permissions need to be enabled

The following operation permissions are required for this collector:

ec2:DescribeInstances

X. Appendix

Refer to the official AWS documentation: