keepcalculator

06 Numbers and Powers

Tracking Cloud Resources Created by AI Agents

Card No. 06·65653 · Updated · Standard formula, shown below

This guide shows you how to track cloud resources that AI agents create, so you can keep costs under control, maintain security, and avoid orphaned resources. You’ll learn a practical tagging and monitoring strategy that works across AWS, Azure, and Google Cloud, plus how to set up alerts and automate cleanup.

What You’ll Need

  • Access to your cloud provider’s console (AWS, Azure, or Google Cloud) with permissions to create IAM roles/policies and view billing.
  • A cloud billing or cost management tool (native tools like AWS Cost Explorer, Azure Cost Management, or GCP Billing Reports work fine).
  • Basic familiarity with your provider’s CLI (optional but helpful).
  • A naming convention or tagging strategy decided in advance.

Step-by-Step

  1. Define a tagging standard. Decide on mandatory tags for every resource: created_by (e.g., ai-agent), agent_name, purpose, and expiry (optional). Use a consistent format like agent-name for the value.
  2. Create an IAM role for your AI agent. In your cloud provider, create a role that the agent will assume. Attach a policy that allows it to create resources (EC2, S3, Azure VMs, GCP Compute Instances, etc.) but requires that all resources be created with tags. For example, in AWS you can use a condition in the IAM policy: "StringEquals": {"aws:RequestTag/created_by": "ai-agent"}.
  3. Configure the agent to use that role. In your agent’s configuration (e.g., an automation script, a CI/CD pipeline, or a dedicated agent platform), set the credentials to assume the role you just created. Ensure the agent includes the mandatory tags on every API call.
  4. Set up a tag-based cost report. In your cloud provider’s cost management tool, create a cost report that groups by the created_by and agent_name tags. This gives you a daily or monthly view of what each agent is spending.
  5. Enable resource inventory tracking. Use your provider’s resource inventory service (AWS Config, Azure Resource Graph, GCP Asset Inventory) to continuously list all resources. Create a query that filters for resources with the created_by=ai-agent tag. This becomes your single source of truth.
  6. Set up alerts for anomalies. In your cost management tool, create a budget with an alert threshold (e.g., 80% of monthly forecast). Also set up a rule that triggers if the number of resources tagged created_by=ai-agent grows by more than a certain percentage in a day. Use CloudWatch (AWS), Azure Monitor, or Cloud Monitoring (GCP) to send email or Slack notifications.
  7. Automate cleanup of orphaned resources. Write a script (e.g., a Lambda function) that runs daily, lists all resources with the created_by=ai-agent tag, and checks the expiry tag. If the expiry date is past, the script deletes or stops the resource. Start with a dry-run mode that logs what it would do.
  8. Review and refine. Once a week, review the cost report and the resource inventory. Adjust tags, budgets, and cleanup policies as needed. Keep a changelog of what you changed and why.

Common Mistakes

  • Not enforcing tags at the IAM level. If you only ask the agent to tag resources but don’t enforce it, the agent might create untagged resources, which then become invisible in your reports.
  • Using inconsistent tag names. Mixing created-by and created_by across resources breaks your filters. Stick to one convention.
  • Forgetting to tag volumes, snapshots, and other attached resources. In AWS, EC2 volumes and snapshots are separate resources. If you tag only the instance, the volume remains untagged and won’t show up in your cost report.
  • Assuming the agent will clean up after itself. Agents often fail mid-task or are killed, leaving resources behind. Always have a separate cleanup process.
  • Setting the expiry tag too far in the future. A 30-day expiry for a temporary test environment is fine, but if you set it to 90 days, you might forget about it and incur costs for months.

Tips

  • Use a prefix for agent-created resources. Name resources like agent-- to make them easy to identify in the console.
  • Leverage cloud provider’s native tagging tools. AWS Resource Groups & Tag Editor, Azure Tags, and GCP Labels all allow bulk tagging and searching.
  • Create a separate AWS account or Azure subscription for agent experiments. This isolates costs and makes cleanup easier—just delete the whole account if needed.
  • Use Infrastructure as Code (IaC) where possible. If your agent can create resources via Terraform or CloudFormation, you can bake tags into the template, ensuring consistency.
  • Log all API calls. Enable CloudTrail (AWS), Activity Log (Azure), or Cloud Audit Logs (GCP) to see exactly which agent created which resource and when. This helps with troubleshooting and security audits.

Troubleshooting

  • Resources are not showing up in the cost report. Tags may take up to 24 hours to appear in cost reports. Also, verify that the resources actually have the tag by checking the console or using the CLI. If they don’t, check the IAM policy—it might not be enforcing tags correctly.
  • The agent fails to create resources with tags. The IAM policy might be too restrictive. Test with a simple resource creation and check the error message. Common issues: the condition key is misspelled, or the policy doesn’t allow the TagResource action.
  • Cleanup script deletes resources that are still in use. Add a “last used” check or require a manual confirmation for resources older than a certain age. Also, ensure the script only targets resources with the exact created_by tag.
  • Alerts are too noisy. Adjust the threshold or the evaluation period. For example, alert only if the cost increases by 20% compared to the same day last week, not just any increase.
  • Can’t see tags in the billing report. Some cloud providers require you to activate cost allocation tags in the billing console before they appear. In AWS, go to Billing Preferences and enable the tags you want to track.

Frequently Asked Questions

Can I track resources without tags?

Yes, but it’s much harder. You could use the resource’s creation timestamp and the IAM user/role that created it (from CloudTrail logs), but that requires cross-referencing multiple sources and is error-prone.

What if my AI agent uses multiple cloud providers?

Apply the same tagging strategy across all providers. Use a unified tool like a multi-cloud cost management platform, or maintain separate reports and combine them manually.

How do I set a default expiry tag?

Some providers allow default tags at the account or project level. In AWS, you can use a service control policy (SCP) to add a default tag if one is missing, but that’s complex. Simpler: have your agent always include an expiry tag with a default value like 7d.

Can I track resources created by a specific agent version?

Yes, add a agent_version tag. Then you can filter cost reports and inventory by that tag to see if a new version is more resource-hungry.

Is it possible to track resources that the agent creates indirectly (e.g., via a service like Lambda)?

Yes, but you need to ensure the Lambda function itself is tagged with created_by=ai-agent. Then, in your inventory tool, you can query for resources that have a reference to that Lambda (e.g., via CloudWatch logs or API calls). This is more advanced and may require custom scripts.

What should I do if I find untagged resources?

First, identify who created them via CloudTrail logs. Then, tag them retroactively or delete them if they’re not needed. Going forward, enforce tagging more strictly.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →