This topic describes a program that is used to automatically add creator tags to new resources. These tags indicate the users that create the resources. This program improves the efficiency of cost allocation. You can use the trail feature provided by ActionTrail to implement this program.
Prerequisites
The following Alibaba Cloud services are activated:
- Resource Access Management (RAM)
- ActionTrail
- Function Compute
- Log Service
Introduction
ActionTrail records the operations logs of an Alibaba Cloud account. These logs can be consumed in real time. In this case, you can deploy a consumption program. When the program processes a resource creation event, it calls the related Tag API operation and adds a creator tag to the resource that you want to create. This way, you can allocate the costs of this resource in the User Center based on the tag. The following figure shows the detailed process.

- Create a trail in ActionTrail.
You can use the trail feature provided by ActionTrail to record operations logs on the cloud and ship these logs to Log Service.
- Consume log data in Log Service.
You can use Function Compute, Apache Flink, or a custom program to consume log data. In this topic, Function Compute is used.
After the log data is consumed, Function Compute calls the related Tag API operation to add a creator tag to the resource that you want to create.
- View bills in the User Center.
You can use the Split Bill, Bill Analysis, or Cost Center feature to view the bills of the resource based on the creator tag.
Deploy a consumption program
In this section, a consumption program is deployed to add a creator tag to a new virtual private cloud (VPC).
(Optional) Delete resources
Run the following command to delete all resources created in the program. After the resources are deleted, the consumption program becomes unavailable.
./uninstall.sh
(Optional) Modify a resource type
The preceding program can be used to automatically add creator tags to the following types of resources:
- Elastic Compute Service (ECS): ECS instances, cloud disks, snapshots, security groups, images, key pairs, and launch templates
- ApsaraDB RDS instances
- Server Load Balancer (SLB) instances
- VPC: VPCs and vSwitches
You can also modify the configuration file of the program to enable the program to support more resource types. These resource types must support ActionTrail and tags. For more information, see Types of resources that support ActionTrail and Alibaba Cloud services that support tags.