The cost command reads your deployed stages and lists ways to lower their AWS cost. A finding carries a dollar amount and a config change only when the command could check that the change is safe and saves what it says. Everything else is listed as worth a look, without an amount.
The command only reads. It sends only the AWS reads the scan needs, from a fixed list; anything else, a write or another read, is refused before it is sent. Without a sign-in it sends nothing to Stacktape. Signed in, it reads your organization's stage types from the Console and, when the scan's total counts every charge, sends three things to get your fee estimate: your organization's ID, the scanned AWS account's ID and the total monthly saving of the priced changes. Findings, configs and resource names stay on your machine. The CLI's anonymous usage telemetry, unless you turned it off, records that the command ran, as for any command.
Usage
API reference
stacktape costCLI options-r, --regionrequired"us-east-2" | "us-east-1" | "us-west-1" | "us-west-2" | "ap-east-1" | "ap-south-1" | "ap-northeast-3" | "ap-northeast-2" | "ap-southeast-1" | "ap-southeast-2" | "ap-northeast-1" | "ca-central-1" | "eu-central-1" | "eu-west-1" | "eu-west-2" | "eu-west-3" | "eu-north-1" | "me-south-1" | "sa-east-1" | "af-south-1" | "eu-south-1"AWS Region
The AWS region for the operation. For a list of available regions, see the AWS documentation.
For commands such as deploy, this flag overrides the project's configured region. If you omit it, Stacktape checks the project's config, AWS_DEFAULT_REGION, the default saved with defaults set, then the AWS profile.
-h, --helpstringShow Help
If provided, the command will not execute and will instead print help information.
--log-level"info" | "debug" | "error"Log Level
The level of logs to print to the console.
info: Basic information about the operation.error: Only errors.debug: Detailed information for debugging.
-p, --profilestringAWS Profile
The AWS profile to use for the command. You can manage profiles using the aws-profile:* commands and set a default profile with defaults set.
For commands that use a connected AWS account, --profile (or AWS_PROFILE) selects the connected account the profile belongs to, unless --aws-account is set. The command fails if that account is not connected.
--projectstringProject Name
The name of the Stacktape project for this operation.
Commands that target a stack take it from projectName in the project's config when the flag is absent.
--quietbooleanQuiet
Hide progress, banners, success messages and hints. Command output, warnings and errors are still printed.
-s, --stagestringStage
The stage for the operation (e.g., production, staging, dev-john). You can set a default stage using the defaults set command. Stage names use lowercase letters, numbers and dashes, with at least 2 characters. The project name, a dash and the stage form the CloudFormation stack name, which can have at most 128 characters. Stacktape shortens an AWS resource name that would be too long and adds a hash.
Credentials
The command uses your own AWS credentials: the profile from --profile or AWS_PROFILE, or credentials in the environment. It does not take --aws-account and never uses an AWS account connected in the Stacktape Console, so it needs no Stacktape account.
When you are signed in, it also reads the stage types chosen in the Console. If that read fails, every stage counts as production.
What it reads, and what that costs
For each stack the command reads its resources from CloudFormation, the sizes of its services, databases, bastions and functions, their deployment and RDS event history, the config the last deploy uploaded, and 14 days of hourly CloudWatch metrics. For a database that may fit a smaller class, it also reads which classes AWS offers for its engine version, the storage bandwidth of those classes, and whether the database can be resized with a short pause.
AWS bills metric reads at $0.01 per 1,000 metrics. A stage with a dozen resources needs about 30 to 100 metrics, so a scan costs a fraction of a cent. The command says this before it starts and prints the number of metrics it read at the end.
Prices are the same AWS list prices stacktape deploy uses: the copy bundled with the CLI, read from AWS before each release. The output shows their date.
Only sizes, counts, dates and identifiers leave the AWS calls. Environment variables, secrets and tags are never copied into the output or logs. The deployed config is read only to estimate the stage and find its stage type, and nothing from it is printed.
What the output shows
For each stage, the answer comes first:
- A summary line: what the stage costs now, how many changes there are and what the priced ones save together, and how many findings are worth a look.
- Changes with an amount, largest first, then those without one. Each has the evidence, the warnings and the config edit. A change meant for its stage only (
stageScoped) also shows the TypeScript that applies it to that stage and keeps other stages as they are, for examplemultiAz: stage === 'staging' ? false : true. A YAML config applies to every stage that deploys it, so deploy that stage from a config file of its own instead. - Worth a look: findings only you can judge, with what was seen and no estimate. Where list prices give a ceiling, such as the same capacity on arm64, the output shows it as "up to". They never count towards a total.
- Not checked yet: rules that need more days of metrics than the stage has, or than a resource has at its current size, with the days each needs and has.
- The monthly estimate of the deployed config, as
stacktape deployshows it, plus what depends on use at the rate seen in the last 14 days (NAT data, function time and requests, incoming and stored logs). Other per-use charges, such as HTTP API requests, queue requests or S3 storage, are not measured or have no price: the output names them and the amount reads "at least". When a charge that bills whatever the traffic has no price, or a resource as deployed differs from its config (storage that grew, a size changed outside the config), the stage's cost is unknown, and the output says why instead of showing a lower number. All amounts use a 30-day month, asstacktape deploydoes.
Then the totals. Findings on the same resource overlap, so the total is not their sum. The command applies the priced changes together and prices the stage once. A saving is computed on the same basis as the cost now and is never larger than what the change affects costs now; when that cannot be checked, the change is shown without an amount. When some per-use charges are not measured, the total adds up everything that is priced and reads "from $X a month", and a "Not counted" line names the charges it leaves out. When any stage's cost is unknown, there is no total. The fee line needs a total that counts every charge. When stages sleep, a line under the total says how each one is counted and how many other stages do not sleep.
All amounts are AWS list prices for the scanned stacks in one region. They do not include credits, savings plans, reserved capacity, other regions or other accounts.
The Stacktape fee
When you are signed in, your role can see billing and the scanned AWS account is connected to your organization, the fee line is an estimate on your plan. The Console applies the same fee rules monthly billing uses to the managed AWS spend reported for last month, and to that spend lowered by the priced saving. It is an estimate, not a charge: billing charges later and may charge another amount. Custom terms and waivers are included; an Enterprise plan gets no amount. When the scanned account is not connected to your organization, its savings do not change your fee, and the command shows the what-if and says so.
Otherwise, or when the Console has no reported month yet, the fee line is a what-if: "if these stacks were all the AWS spend Stacktape manages for you". It uses the published fee: the Free plan has no fee up to $200 of managed AWS spend a month, and above that Flexible charges one rate on the whole month's spend. A lower bill can fall into a band with a higher rate, so the command computes the fee on both sides.
It then shows two results:
- Already paying the fee: AWS plus fee now, minus AWS plus fee after.
- Not paying Stacktape yet: AWS now, minus AWS plus the whole new fee after. When the fee is larger than the AWS saving, the command says so. You can apply every change yourself with the open-source CLI for free.
Production and non-production stages
Some changes are offered only on a stage that is positively non-production. The command decides the type in this order:
stackConfig.stageTypein the deployed config.- The type chosen for the stage in the Stacktape Console, when you are signed in.
- The stage name, when it contains only non-production words such as
dev,staging,testorpr-12.
A name that says nothing, such as main or acme, counts as production. So does a stage whose deployed config or Console type could not be read. The output names what decided the type of each stage, and a change offered because of the name says so: set stageType if the name is wrong.
Findings
A change is offered only when the installed Stacktape accepts its exact edit: the option and the value. An option a later release adds turns its finding into worth a look until you upgrade.
| Finding | Amount and edit when | Otherwise |
|---|---|---|
| A non-production stage runs all day | Every entry point was found and its requests read for 7 days, nothing in the stage works without a request, and Stacktape accepts the sleep edit. A CloudFront distribution, REST, WebSocket or AppSync API, function URL or network load balancer counts as an entry point the scan cannot read. The amount is what sleep stops outside the proposed awake hours (Fargate services, databases without read replicas, NAT instances, bastions), with each awake period lengthened by the wake that starts before it and the time it takes to go to sleep (10 minutes, or 19 with a database), minus what sleep itself adds (its stage check and its custom metric). Something sleep keeps running (keepAwake, what those resources connect to, services on EC2 instances) keeps billing, and a stage with nothing to stop gets no amount. Storage, load balancers, NAT gateways and Aurora storage keep billing. Edit: stackConfig.sleep.awakeHours, in UTC. | Worth a look, with the reason. Nothing on a production stage, a stage whose type is unknown, or a stage that already sleeps. |
| Oversized Fargate service | One task without scaling, 7 days at its current size with CPU data for 90% of hours, and a smaller CPU that allows the same memory, holds the CPU its containers reserve and keeps the peak under 70%. Edit: cpu only. | Nothing. Memory is never resized: ECS does not record its peak. |
| EC2 instances of a container workload may be too large | Never. | Worth a look when cluster CPU and memory stayed under 40%. |
| Oversized database | A PostgreSQL, MySQL or MariaDB instance without read replicas, 7 days at its class, and a smaller class of the same family that AWS offers for its engine version and storage keeps CPU under 60%, a quarter of its memory free, connections under half the default limit, storage throughput and IOPS under 70% of the class's baseline and, for db.t classes, every hour's average CPU at its baseline. The smallest such class is proposed. The output says whether the move can happen with a pause of about 15 seconds or needs a plain resize of about two minutes. Edit: instanceSize, then stacktape database resize applies it. | Worth a look when CPU, memory and connections fit the next smaller class but the rest could not be checked, and for Aurora. |
| Provisioned Aurora that may be cheaper on Serverless v2 | Never. | Worth a look, with the break-even capacity. |
| Non-production service not on Spot | Never an estimate: AWS publishes no Fargate Spot prices, so the output shows only AWS's stated maximum, "up to about 70% less". Edit: useSpotInstances on a rolling x86 Fargate service. | Nothing. |
| NAT gateway with little traffic | Stacktape's own gateways, 7 days old, whose peaks were read for every hour: under the 5 Gbit/s a t4g.nano bursts to, no hour above half the 32 Mbit/s it sustains, and at most 65,536 connections at once. The peaks come from CloudWatch periods, so a burst shorter than a period does not show. The amount includes each instance's address, its disk and an estimate of the failover check. Edit: stackConfig.nat: ha-ec2. | Worth a look, with the peak throughput and connections. |
| Database standby on a non-production stage | Plain RDS, and both the Multi-AZ and the Single-AZ prices of its instance and storage are known. Edit: multiAz: false. | Nothing. |
| Long log retention | Never: how old the stored logs are is not known. | Worth a look above 14 days outside production, 90 in production. |
| x86 that may run on arm64 | Never. | Worth a look, with the list-price difference as the most it can save ("up to $1.78 a month"). Whether the code runs on arm64 is the open question. |
| Load balancer with no requests | Never. | Worth a look after 14 days without any response: no request to a target, redirect, fixed response, or 4xx or 5xx of its own (such as an authentication 401). |
| Preview stage with no deploy for 14 days | Never. | Worth a look on a stage a trusted source marks as a preview. A name like pr-12 is not enough. |
| Protected database on a preview stage | Never. | Worth a look, on a trusted preview only. |
On a stage that already sleeps, the scan prices what its sleep stops (container tasks with their addresses, database
instances, NAT instances and bastions) only for the hours awakeHours keep it awake. With whenIdle as well, it adds
afterMinutes to each awake period, so an amount is never more than the real saving. With only whenIdle, or sleep by
hand, nobody can tell how long the stage sleeps: the whole month is counted, the amount reads "if always awake", and a
database standby gets no amount. A
scan that runs while the stage is asleep prices the task count and instance types the deployed config runs when awake.
A metric that could not be read is unknown, never zero. With too little data, a rule makes no finding; when the reason is too little history, the output says so under "Not checked yet".
Agent mode
With --agent, the command returns JSON with schemaVersion: "stacktape.cost.v1". moneyFields explains every amount in it. A stage's knownMonthlyUsd is null when its cost is unknown (unknownBecause), and a lower bound when lowerBound is true (notMeasured). A stage's assumes says how its amounts count sleep: schedule, from-schedule (the lowest the bill can be), if-always-awake (whenIdle only or sleep by hand) or none. totals.sleep is none, some or all, and totals.assumes lists how each sleeping stage is counted. totals.kind is exact, from or unknown. It is from when totals.nowUsd is the lowest the bill can be: totals.notMeasured lists the per-use charges it does not count, or a sleeping stage is counted at its schedule's minimum. It is unknown when totals.nowUsd is null. When the total is unknown or totals.notMeasured is not empty, fee.kind is withheld. Otherwise, fee.kind is plan-estimate when the Console estimated your fee on your plan (its amounts are named estimatedFeeUsd and estimatedFeeAfterUsd, and none of them is a charge), and what-if otherwise, with fee.note saying why your plan was not used. fee.label always says what the numbers are. A stage's notCheckedYet lists the rules that need more days of history (minimumDays) than the stage or a resource has (observedDays).
Each finding has a stable key, its evidence, warnings and risk. A finding with kind: "change" has ordered edits. An edit names the config path, the values it expects to find there and the value it sets. Apply a finding's edits all together, and only when every expect matches the current config. stageScoped: true means the change is for that stage only: use a stage condition in a TypeScript config. A finding with kind: "investigate" has no edits and no amount. A finding without an estimate may carry savingUpTo, the most it can save: basis: "list-price" with monthlyUsd from the difference in list prices, or basis: "aws-stated-maximum" with the percent AWS states. It never counts towards a total.
There is no automatic fix: a coding agent or you apply the edits.
Related commands
stack list: list the stacks in a region.deploy: apply the config changes.