Automating AWS Cost Optimization with an AI Agent

How Optimize turns the AWS cost audit into a daily loop: one read-only role, anomalies flagged a day or two after AWS bills them, and a NAT gateway spike investigated to a verified Quick win. Nothing changes until someone selects Implement.

GuideUpdated Nov 2, 2026

Cover Image for Automating AWS Cost Optimization with an AI Agent

Automating AWS Cost Optimization with an AI Agent: From Monthly Audits to Daily Savings

On the 3rd of the month, someone exports last month's Cost Explorer data and sees NAT gateway charges doubled. The traffic behind it started on the 9th of the previous month. It billed for 25 days before anyone looked, and it'll bill for another week or two while a ticket finds an owner. Nothing about the audit was wrong. It was late, the way monthly audits always are.

This part closes the lateness. Optimize reads your AWS billing data every day, flags a jump like that within a day or two of AWS billing it, and investigates it with the same commands you ran by hand in part two. A scan never changes anything. The change waits for you.

Why the audit can't keep up

Part two's audit has four limits, and none of them is effort. It's a snapshot of one day. It costs engineer hours every time, so monthly drifts to quarterly. Its findings decay as traffic shifts. And it ends at a ticket.

The deeper problem is the judgment step. Every finding needs checking before anyone acts: is the instance idle or quiet between batch runs, does anything restore from that snapshot, does a bucket policy depend on the NAT's address. That checking is what gets skipped when the audit runs long, and skipping it is how a cost ticket turns into an incident. Doing it faster takes the same evidence, gathered by something that doesn't get tired at finding forty.

Connecting AWS: one read-only role, about five minutes

01Your account

AWSAWS

  • Cost ExplorerUp to 13 months of billing history
  • EC2, EBS, RDS, ELB, VPCThe resources behind each billed service
  • CloudWatchThe metrics behind each finding

One role, ReadOnlyAccess, External ID

02Optimize

CloudThinkerCloudThinker

  • ScanRead-only checks of every billed service
  • Daily refreshNew billing data, Cost Health, anomalies
  • InvestigateEvidence badge and estimate on every finding

Short-lived STS credentials

03Your team

Findings board

  • TriageStatus, assignee and discussion per finding
  • ReportsGenerated now or on a schedule
  • ImplementThe change, through Auto Mode

Nothing changes until someone acts

The same APIs you used in part two, read every day instead of every quarter.

You open the AWS connection in CloudThinker, and the dialog generates an External ID and a setup script. You paste the script into CloudShell. It creates CloudThinkerAccessRole with a trust policy that only CloudThinker can assume, and only with your External ID, attaches the AWS managed ReadOnlyAccess policy, and prints the role ARN. CloudThinker assumes the role through STS and gets short-lived credentials, so there's no long-lived key to leak. Every session shows up in CloudTrail under a cloudthinker- session name.

Two prerequisites trip people up. Cost Explorer must be turned on in the account, and AWS can take up to 24 hours to activate it. And in an AWS Organization, Optimize reads only the connected account's own spend, even from the management account, so connect each member account you want covered.

Where the seven leaks show up

The first scan pulls up to 13 months of billing history, then checks each billed service with read-only commands. After that, a daily refresh pulls new billing data, rescores Cost Health and looks for anomalies. Part one's leaks land in three places:

Leak from part oneWhere it shows up
Unattached EBS, old snapshotsFindings on idle or unused resources
Idle or oversized EC2 and RDSFindings on oversized resources
Savings Plans and RI coverageFindings on commitment coverage
Elastic IPs, idle load balancersFindings on unused resources
NAT and cross-AZ transferFindings on the billed service, and an anomaly when it jumps
Non-prod running 24/7Cost Health's allocation checks flag the missing tags

Each finding carries an estimated monthly saving, effort, risk, whether the change is reversible, and an evidence badge that says how the agent knows. The ones that matter most are often the ones that arrive between scans, as anomalies.

01Refresh

Daily billing

New billing data lands a day or two after usage.

02Detect

Anomaly

A service passes its 14-day median by enough to matter.

03Investigate

Test readings

Usage types, resources and the checks that would make a fix wrong.

04Finding

Evidence badge

An estimate, effort, reversibility and how the agent knows.

05Implement

Your call

The change runs in the account only when someone selects it.

Step three is the one a manual audit skips when it runs short on time.

One anomaly, investigated

Here's the NAT gateway jump from the opening, the way Optimize works it. The details are illustrative.

The anomaly. Optimize compares each service's daily cost with the median of the previous 14 days. On the 11th, once AWS has billed the 9th, "EC2 - Other" sits far enough above its baseline to pass both detection gates. The card shows actual cost, baseline and estimated impact, all from billing data. Someone selects Investigate with CloudThinker, and a conversation opens with the anomaly's evidence and the exact AWS connection already in scope.

Three readings, three predictions.

01Reading 1

S3 through the NAT

Predicts a VPC with no S3 gateway endpoint and a new workload reading from S3.

02Reading 2

Cross-AZ routing

Predicts subnets routed to a NAT in another AZ, with inter-AZ charges rising too.

03Reading 3

New internet egress

Predicts a service calling an external API or pulling from a public registry.

Each reading predicts different evidence. The investigation checks the predictions, not the headline.

Which usage type, which gateway? Splitting "EC2 - Other" by usage type puts the increase in USE1-NatGateway-Bytes. Inter-AZ transfer didn't move, which makes the second reading unlikely. Bytes processed per gateway (BytesInFromSource plus BytesInFromDestination, since processing is billed both ways) puts almost all of it on one NAT gateway in vpc-0abc, starting the 9th.

Is there an S3 endpoint?

aws ec2 describe-vpc-endpoints \
  --filters Name=vpc-id,Values=vpc-0abc Name=service-name,Values=com.amazonaws.us-east-1.s3 \
  --query 'VpcEndpoints[*].{ID:VpcEndpointId,Type:VpcEndpointType,State:State}'

Empty. vpc-0abc was created on the 8th for a new data pipeline, from a template that doesn't add endpoints, and the pipeline's role reads from three S3 buckets. VPC Flow Logs aren't on for that VPC, so the destination can't be proven to the byte. The timing and the missing endpoint make the first reading the strong one, and the conversation says that in those words.

The check that makes the fix safe. A gateway endpoint changes the source address S3 sees, from the NAT's public IP to a private one. Any bucket policy that allows access by aws:SourceIp would start denying the pipeline. So the agent reads each policy:

aws s3api get-bucket-policy --bucket pipeline-raw \
  --query Policy --output text | jq '.Statement[].Condition'

None of the three uses aws:SourceIp.

The finding. It lands in the anomaly's Explained by list:

Add an S3 gateway endpoint to vpc-0abc. About 14 TB a month of pipeline reads from S3 go through the NAT gateway since the 9th, roughly $630 a month at $0.045 per GB. The VPC has no S3 gateway endpoint, and no bucket policy depends on source IP. Evidence: Verified. Effort: Low. Reversible: yes, delete the endpoint. Class: Quick win.

Found on day two instead of day 25, with the access risk already checked.

You decide what changes

Nothing above changed the account. When the platform team agrees, someone selects Implement on the finding, and CloudThinker makes the change:

aws ec2 create-vpc-endpoint --vpc-id vpc-0abc \
  --vpc-endpoint-type Gateway \
  --service-name com.amazonaws.us-east-1.s3 \
  --route-table-ids rtb-0priv1 rtb-0priv2

Implement first checks that the resource still matches the finding, and stops if a dependency would break or there's no way to roll back. The write goes through Auto Mode, so you decide what runs on its own and what waits for approval. Commitment purchases and production resizes are the obvious ones to keep behind a person.

One practical detail: the setup script's ReadOnlyAccess role can analyze a finding but can't change anything. To use Implement, add only the write permissions the change needs (here, creating a VPC endpoint) and leave Allow writes on for the connection.

How to read the first Findings board

These rows are illustrative, the kind of board a first scan produces on a busy production account. Your account will differ.

FindingClassEvidenceEst. monthly
23 unattached EBS volumes, 4.1 TBQuick winVerified~$330
14 instances one size too largeNeeds reviewVerified~$2,000
Savings Plans coverage at 41%Needs reviewInferred~$4,800
2 RDS instances at 8% CPUNeeds reviewVerified~$1,050
S3 traffic through a NAT gatewayQuick winVerified~$630
m5.4xlarge cache at 6% CPUNo actionVerifiedNot counted

Read two rows before you add up the column. The rightsizing and Savings Plans rows estimate savings on the same compute spend: shrink the instances and the commitment you need shrinks too. That's why Optimize calls the total an upper bound and tells you not to subtract it from the forecast. And the last row is a finding too. The cache is memory-bound and doing its job, and "we checked this and it's fine" saves the next reviewer an hour.

Why this beats the traditional approach

Monthly or quarterly auditOptimize
When waste is foundWeeks after it startsA day or two after AWS bills it
VerificationDone when there's timeAn evidence badge on every finding
Justified spendRediscovered every auditRecorded as No action
The totalOverlapping items added upLabeled an upper bound
From finding to fixA ticket that needs an ownerImplement, through Auto Mode

The deeper difference is where the hours go. In the audit, most of the afternoon goes to collecting evidence and too little to judging it. With the collecting done, your time goes to the one decision that needs a person.

What it won't do

  • Change anything during a scan. Scans read. Only Implement writes, and only with the write permissions you add and the approval Auto Mode requires.
  • Guess a cause. If the access or the data can't establish why spend moved, the investigation says so.
  • Promise the total. Potential savings is an upper bound. Optimize doesn't track realized savings, so check a full billing month after the change.
  • Make architectural calls. It'll tell you a NAT gateway carries 14 TB of S3 traffic. Whether to redesign the VPC stays an engineering decision.

Getting started

Connect an AWS account with the read-only role, let the first scan finish, and ask your first question:

"Why did EC2 - Other go up this month? Break it down by usage type and tell me which resources drove it."

"Which open findings on this account are Quick wins, and which need someone to confirm them first?"

"Recommend a Savings Plans commitment for our stable baseline, with the break-even point and what happens if usage drops 20%."

"Which non-production instances ran between midnight and 6 a.m. last week, and what would a business-hours schedule save?"

Next step: run the first prompt on the account whose bill moved most this month. Optimize covers the AWS setup and the Findings board.

Related reading

About the author

ST

Steve Tran

Founder & CTO, CloudThinker

Steve Tran is the founder and CTO of CloudThinker, which builds Frontier Investigation Agents for production cloud operations. He writes about incident investigation, cloud cost, and the practices teams use to safely run autonomous AI agents against production AWS, GCP, and Azure environments.

awscostoptimizationfinopsoptimizeaiagentagenticfinopscloudthinker