Files
floci/docs/services/ce.md
T
Priamo Germosen 58930c9278 fix(iam): derive the request resources without corrections (#8187)
The request-resources generator carried 106 CORRECTIONS over 22
namespaces, each a hand-written entry for one operation. They are gone,
and no Floci service states what an operation acts on either: a service
only looks up what it holds where an entry asks it to. Every operation
the corrections covered is now read from botocore's shapes and
documentation and the Service Reference, or, in two places, from a fix
to the handler whose behavior the correction worked around.

One table stays stated by hand, MEASURED, for what AWS was measured to
check where neither botocore nor the Service Reference says it. The
generator admits an entry only when it links to its measurement, names
types the reference does not list for the action, and gives what the
rules do not; review admits only real AWS evidence. It holds DynamoDB
ListTables, on table/* (#7336's probes and AWS's recorded denial), and
Step Functions SendTaskSuccess, SendTaskFailure and SendTaskHeartbeat,
on the token's activity or state machine (#7277's probes and AWS's
recorded denial). The generator's older hand tables (FOUND_BY, THROUGH,
MINTED_IDS, UNQUALIFIED, QUALIFIED_MEMBERS, ID_TARGETS,
CLIENTS_NOT_READ, READ_IN_HAND_BUILT) are unchanged.

Generator rules: documentation naming the type fills it when it says the
member is a name or an id as the variable is; an ARN head noun, or a
name ending in ArnList, makes an ARN member; fields of a top-level
structure and of the structures in a map are members; the id a create
answers beside another type's ARN is that type's (RunJobFlow's JobFlowId
and ClusterArn); an account-id member fills AccountId; a qualified
member fills first, and a ResourceId variable is the type's own id,
filled by a member named ResourceId before one named after the type. An
ARN member whose pattern names another service, or which its
documentation gives as the ARN of another type of the service, is not
read unless named after a type the action acts on. Each SDK client's
model is read apart, resources the clients disagree on carry their
endpoint, and a v2 load balancer's type is picked by its Type enum and
documented default. A variable no member fills is fixed to the one
value of an enum named after it that the operation's name gives
(CodePipeline's Custom action type owner), and a type named only by an
optional member documented as holding what the operation is about is
reached through that thing when the member is left out (EMR's
ModifyInstanceGroups, through its instance groups).

Reader and service changes: a member left out, or a JSON null, names
the service's default where it has one (Athena's primary workgroup and
AwsDataCatalog, EventBridge's default bus, per PutEvents entry); two
types whose formats differ by one variable are told apart by whether the
member names that default (EventBridge rules); a name for an id variable
is found by the service (Rekognition stream processors, Logs
deliveries); a bare id of the type an operation is about reaches the
acted-on type through its service (the project CodeBuild holds a build
under, the delivery destinations of the source a Logs
DeleteDeliverySource deletes). A member given a JSON null names nothing,
as the handlers read it, wherever the reader fills a variable from it,
so an EMR ClusterId or an IAM Identity Center TargetId of null no
longer names cluster/null or account/null. The table no longer has
absent or before, and the reader refuses a resource key it does not
know.

Checks that change where the old correction had no evidence of AWS
behind it: a Step Functions Local <stateMachineArn>#<test case> is
checked as given; Macie CreateMember on member/*; IAM Identity Center
ProvisionPermissionSet for ALL_PROVISIONED_ACCOUNTS on its instance and
permission set alone, the request-scoped account pinning that served the
account check removed; Logs DeleteDeliverySource on its delivery
destinations; a CodeBuild build id of no build Floci holds on *.

Handler fixes: Athena's ListDatabases, ListTableMetadata and
GetTableMetadata read Glue whichever catalog was named, so they were
also checked on AwsDataCatalog. They now refuse a catalog whose metadata
is not the account's Glue Data Catalog with MetadataException and are
checked on the catalog they name. Cost Explorer's cost reads ignored
BillingViewArn, so they were checked on *. They now answer the primary
billing view alone, refuse another with ResourceNotFoundException, and
are checked on the view they name.

The passed-roles table had drifted from the Service Reference and is
regenerated. AWS now passes CreateTrainingSession's role to
training-session.sagemaker alone, so its RoleArn is read rather than
left unread for naming two services, and AWS lists Secrets Manager's new
AssociateCrossAccountReplica, which the pinned botocore does not model
yet. The generator now leaves an operation no pinned model has unread on
its own, until a bump brings it in, in place of a hand-written entry for
each, so the two there were are gone.

The tag-on-create table had drifted too: AWS no longer lists a tagging
action for Network Firewall's CreateProxy, CreateProxyConfiguration and
CreateProxyRuleGroup, and lists five operations the pinned botocore
does not model yet. It is regenerated.
2026-11-13 22:40:31 -04:00

8.7 KiB
Raw Blame History

Cost Explorer (ce:*)

Protocol: JSON 1.1 Header: X-Amz-Target: AWSInsightsIndexService.<Action> Endpoint prefix: ce

Floci synthesizes Cost Explorer responses from its own resource state, multiplied by the bundled AWS Pricing snapshot served by the Pricing service. Costs reflect what's running in Floci right now, so any test that mutates resources (e.g. creates a bucket, runs an instance) sees those changes in the next GetCostAndUsage call.

Floci answers the costs of the account as a whole, which AWS gives as the caller's primary billing view. AWS does not document that view's ARN, so Floci takes it as arn:aws:billing::<account>:billingview/primary. GetCostAndUsage, GetCostAndUsageWithResources, GetDimensionValues, GetTags and GetCostCategories accept that view or none in BillingViewArn, and refuse any other with ResourceNotFoundException, as AWS does for a view it does not hold. With IAM enforcement on, they are checked on the view they name.

Supported Actions

Action Description
GetCostAndUsage Full TimePeriod / Granularity / Filter / GroupBy / Metrics support
GetCostAndUsageWithResources Same shape as GetCostAndUsage; for resource-level breakdown, group by Type=DIMENSION,Key=RESOURCE_ID
GetDimensionValues Returns dimension values present in the synthesized data set
GetTags Returns tag keys / values across enumerated resources
GetReservationCoverage Stub; returns zeroed totals; full RI math lands in a follow-up PR
GetReservationUtilization Stub; returns zeroed totals
GetSavingsPlansCoverage Stub; returns empty list
GetSavingsPlansUtilization Stub; returns zeroed totals
GetCostCategories Stub; returns empty list (cost-category management not yet emulated)
CreateAnomalyMonitor Store a dimensional or custom monitor with optional resource tags
GetAnomalyMonitors List account-scoped monitors with ARN filters and pagination
UpdateAnomalyMonitor Update a monitor's name
DeleteAnomalyMonitor Delete a monitor without deleting subscriptions
CreateAnomalySubscription Store subscriber, frequency, monitor, and threshold configuration
GetAnomalySubscriptions List subscriptions with ARN or monitor filters and pagination
UpdateAnomalySubscription Update supplied settings while preserving omitted fields
DeleteAnomalySubscription Delete a subscription
ListTagsForResource Read monitor or subscription tags
TagResource Add or replace monitor or subscription tags
UntagResource Remove monitor or subscription tag keys

Cost anomaly configuration

Monitors and subscriptions support creation, listing, updates, deletion, and resource tags. They are global within the calling account: requests signed for different regions see the same resources, while another account cannot read or modify them. Definitions and tags use Floci's configured storage and survive restarts in persistent storage modes.

DIMENSIONAL monitors support SERVICE, LINKED_ACCOUNT, TAG, and COST_CATEGORY. Tag and cost-category monitors provide a key in MonitorSpecification; CUSTOM monitors provide linked-account, tag, or cost-category values. MonitorSpecification is a JSON object, including when the caller's configuration tool represents it internally as a JSON string.

Subscriptions support DAILY or WEEKLY email configuration and IMMEDIATE SNS configuration. Updates preserve omitted fields and reject invalid changes before writing. The deprecated Threshold input is accepted as an absolute-cost shorthand; reads return its normalized ThresholdExpression. Monitor names are labels, not idempotency keys.

GetAnomalyMonitors and GetAnomalySubscriptions accept their ARN-list filters, MaxResults, and NextPageToken; subscriptions also support a MonitorArn filter. Tags are managed through ResourceArn, ResourceTags, and ResourceTagKeys, and are not embedded in the resource definitions returned by the list APIs.

Deleting a monitor leaves subscriptions intact and editable. In this emulator, their saved monitor ARN lists remain unchanged until explicitly updated. Monitor evaluation, anomaly generation, email confirmation, and email/SNS notification delivery are not emulated. Floci does not synthesize subscriber confirmation status or a monitor's last evaluation date. Organizations management-account eligibility is not enforced for the additional dimensional monitor types.

For example, create a monitor and a daily subscription against the local endpoint:

MONITOR_ARN=$(aws ce create-anomaly-monitor --endpoint-url http://localhost:4566 \
  --anomaly-monitor '{"MonitorName":"services","MonitorType":"DIMENSIONAL","MonitorDimension":"SERVICE"}' \
  --resource-tags Key=Environment,Value=development --query MonitorArn --output text)

aws ce create-anomaly-subscription --endpoint-url http://localhost:4566 \
  --anomaly-subscription "{\"SubscriptionName\":\"daily-alerts\",\"Frequency\":\"DAILY\",\"MonitorArnList\":[\"$MONITOR_ARN\"],\"Subscribers\":[{\"Address\":\"alerts@example.com\",\"Type\":\"EMAIL\"}],\"ThresholdExpression\":{\"Dimensions\":{\"Key\":\"ANOMALY_TOTAL_IMPACT_ABSOLUTE\",\"Values\":[\"100\"],\"MatchOptions\":[\"GREATER_THAN_OR_EQUAL\"]}}}"

Cost synthesis model

Each Floci service that wants to participate in cost reporting ships a {@code @ApplicationScoped} bean implementing ResourceUsageEnumerator (in core/common/). Cost Explorer auto-discovers these via CDI — adding a new service with cost data needs zero changes to CostExplorerService.

The bundled enumerators cover:

Service Priced unit Source
AmazonEC2 BoxUsage:<instanceType> × hours Ec2Service.describeInstances
AmazonS3 TimedStorage-Standard × GB-month S3Service.listBuckets + listObjects
AWSLambda AWS-Lambda-Requests (zero quantity, catalog only) LambdaService.listFunctions
Other Floci services (DDB, SQS, SNS, …) catalog only, zero quantity UnpricedServicesEnumerator

Unpriced services emit zero-quantity catalog rows so they remain visible in GetDimensionValues SERVICE responses without contributing billed cost.

RECORD_TYPE semantics

GROUP_BY=RECORD_TYPE distinguishes:

Record type When emitted
Usage All synthesized usage rows (always present)
Credit When FLOCI_SERVICES_CE_CREDIT_USD_MONTHLY > 0 (see below)
Tax / Refund / DiscountedUsage / SavingsPlan* Reserved for future PRs; not currently emitted

Synthetic credit injection

Set FLOCI_SERVICES_CE_CREDIT_USD_MONTHLY (default 0.0) to emit a monthly Credit row that offsets min(creditUsd, monthly Usage cost). Useful for exercising any code path that computes net cost (gross usage − credits) without having to build credit fixtures by hand.

floci:
  services:
    ce:
      credit-usd-monthly: 100.0

Configuration

Variable Default Description
FLOCI_SERVICES_CE_ENABLED true Enable or disable the service
FLOCI_SERVICES_CE_CREDIT_USD_MONTHLY 0.0 Synthetic monthly credit, applied as a Credit RECORD_TYPE row

Examples

export AWS_ENDPOINT_URL=http://localhost:4566
export AWS_DEFAULT_REGION=us-east-1
export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test

aws ce get-cost-and-usage \
  --time-period Start=2026-01-01,End=2026-02-01 \
  --granularity MONTHLY \
  --metrics UnblendedCost \
  --group-by Type=DIMENSION,Key=SERVICE

aws ce get-dimension-values \
  --time-period Start=2026-01-01,End=2026-02-01 \
  --dimension SERVICE
import boto3

ce = boto3.client(
    "ce",
    endpoint_url="http://localhost:4566",
    region_name="us-east-1",
)

resp = ce.get_cost_and_usage(
    TimePeriod={"Start": "2026-01-01", "End": "2026-02-01"},
    Granularity="MONTHLY",
    Metrics=["UnblendedCost"],
    GroupBy=[{"Type": "DIMENSION", "Key": "SERVICE"}],
    Filter={
        "Not": {"Dimensions": {"Key": "SERVICE", "Values": ["AmazonRDS"]}}
    },
)
for result in resp["ResultsByTime"]:
    for group in result["Groups"]:
        print(group["Keys"], group["Metrics"]["UnblendedCost"]["Amount"])

Out of Scope

  • Forecasting (GetCostForecast, GetUsageForecast).
  • Right-sizing recommendations (GetRightsizingRecommendation).
  • Anomaly evaluation and results (GetAnomalies), email confirmation, and email/SNS delivery.
  • Real Reservation / Savings Plan utilization math — currently zeroed stubs.
  • Cost category management (CreateCostCategoryDefinition / *Definition / ListCostCategoryDefinitions).
  • Resource-level granularity beyond what GetCostAndUsageWithResources exposes today.