Help us shape the future of Go! Take the 2026 Go Developer Survey

budgets

package
v1.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 27 Imported by: 0

README

Budgets

Parity grade: B · SDK aws-sdk-go-v2/service/budgets@v1.53.1 · last audited 2026-10-18 (4ae40e79e)

Coverage

Metric Value
PARITY entries audited 26 (26 ok)
Feature families 5 (4 ok, 1 partial)
Known gaps 9
Deferred items 0
Resource leaks clean
Known gaps
  • CalculatedSpend: spend comes from the Cost Explorer ledger, which is synthetic seed data (90 days), not real usage
  • CalculatedSpend: RI/Savings Plans utilization and coverage budgets report 0 PERCENTAGE; no utilization source is wired
  • CostFilters: AZ, InstanceType, Operation, PurchaseType, UsageTypeGroup, etc. do not narrow spend (the ledger does not model them); FilterExpression is flattened to And-of-Dimensions only, Or/Not/Tags/CostCategories are ignored for spend
  • CostTypes: Include* flags do not change computed spend; only UseAmortized/UseBlended select the metric
  • AutoAdjustData: the limit is recomputed on create/update only, not at period rollover
  • Alerting: SNS delivery uses the default-region SNS backend (topics in other regions are unreachable); topic policies granting budgets.amazonaws.com are not checked; evaluator cadence is 1 minute versus AWS several times a day
  • ExecuteBudgetAction: ExecutionRoleArn is shape-checked only, never assumed or looked up in IAM; SSM actions start AWS-Stop*/Start* automation documents through the SSM backend
  • BillingViewArn: format-checked only; HealthStatus is always HEALTHY
  • AccessDeniedException, ThrottlingException, InternalErrorException, ExpiredNextTokenException, BillingViewHealthStatusException, ServiceQuotaExceededException: never raised

More

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound              = errors.New("not found")
	ErrDuplicateRecord       = errors.New("duplicate record")
	ErrCreationLimitExceeded = errors.New("creation limit exceeded")
	ErrInvalidParameter      = errors.New("invalid parameter")
	ErrInvalidNextToken      = errors.New("invalid next token")
	ErrResourceLocked        = errors.New("resource locked")
)

Sentinels, one per exception the pinned SDK declares and this service raises.

Functions

This section is empty.

Types

type Action

type Action struct {
	ActionThreshold  *ActionThreshold `json:"ActionThreshold,omitempty"`
	Definition       *Definition      `json:"Definition,omitempty"`
	ActionID         string           `json:"ActionId"`
	ActionType       string           `json:"ActionType"`
	ApprovalModel    string           `json:"ApprovalModel"`
	BudgetName       string           `json:"BudgetName"`
	ExecutionRoleArn string           `json:"ExecutionRoleArn"`
	NotificationType string           `json:"NotificationType"`
	Status           string           `json:"Status"`
	Subscribers      []Subscriber     `json:"Subscribers"`
}

Action is a budget action.

type ActionExecutor

type ActionExecutor interface {
	Run(ctx context.Context, accountID string, a Action, reverse bool) error
}

ActionExecutor applies (or reverses) a budget action against IAM, Organizations or SSM.

type ActionHistory

type ActionHistory struct {
	Timestamp            Timestamp            `json:"Timestamp"`
	EventType            string               `json:"EventType"`
	Status               string               `json:"Status"`
	ActionHistoryDetails ActionHistoryDetails `json:"ActionHistoryDetails"`
}

ActionHistory is one action event.

type ActionHistoryDetails

type ActionHistoryDetails struct {
	Message string `json:"Message"`
	Action  Action `json:"Action"`
}

ActionHistoryDetails is the payload of a history entry.

type ActionPatch

type ActionPatch struct {
	ActionThreshold  *ActionThreshold
	Definition       *Definition
	ApprovalModel    string
	ExecutionRoleArn string
	NotificationType string
	Subscribers      []Subscriber
}

ActionPatch holds UpdateBudgetAction fields; zero values are unchanged.

type ActionRecord

type ActionRecord struct {
	Tags      map[string]string `json:"tags,omitempty"`
	Key       string            `json:"key"`
	AccountID string            `json:"accountID"`
	Action    Action            `json:"action"`
	History   []ActionHistory   `json:"history,omitempty"`
}

ActionRecord is a stored budget action with its history and tags.

type ActionThreshold

type ActionThreshold struct {
	ActionThresholdType  string  `json:"ActionThresholdType"`
	ActionThresholdValue float64 `json:"ActionThresholdValue"`
}

ActionThreshold triggers an action.

type AutoAdjustData

type AutoAdjustData struct {
	HistoricalOptions  *HistoricalOptions `json:"HistoricalOptions,omitempty"`
	LastAutoAdjustTime *Timestamp         `json:"LastAutoAdjustTime,omitempty"`
	AutoAdjustType     string             `json:"AutoAdjustType"`
}

AutoAdjustData configures automatic limit adjustment.

type Budget

type Budget struct {
	AutoAdjustData      *AutoAdjustData     `json:"AutoAdjustData,omitempty"`
	BudgetLimit         *Spend              `json:"BudgetLimit,omitempty"`
	CalculatedSpend     *CalculatedSpend    `json:"CalculatedSpend,omitempty"`
	CostFilters         map[string][]string `json:"CostFilters,omitempty"`
	CostTypes           *CostTypes          `json:"CostTypes,omitempty"`
	FilterExpression    *Expression         `json:"FilterExpression,omitempty"`
	HealthStatus        *HealthStatus       `json:"HealthStatus,omitempty"`
	LastUpdatedTime     *Timestamp          `json:"LastUpdatedTime,omitempty"`
	PlannedBudgetLimits map[string]Spend    `json:"PlannedBudgetLimits,omitempty"`
	TimePeriod          *TimePeriod         `json:"TimePeriod,omitempty"`
	BillingViewArn      string              `json:"BillingViewArn,omitempty"`
	BudgetName          string              `json:"BudgetName"`
	BudgetType          string              `json:"BudgetType"`
	TimeUnit            string              `json:"TimeUnit"`
	Metrics             []string            `json:"Metrics,omitempty"`
}

Budget is a budget as stored and returned.

type BudgetNotificationsForAccount

type BudgetNotificationsForAccount struct {
	BudgetName    string         `json:"BudgetName"`
	Notifications []Notification `json:"Notifications"`
}

BudgetNotificationsForAccount groups notifications by budget.

type BudgetRecord

type BudgetRecord struct {
	Tags          map[string]string    `json:"tags,omitempty"`
	Key           string               `json:"key"`
	AccountID     string               `json:"accountID"`
	Budget        Budget               `json:"budget"`
	Notifications []NotificationRecord `json:"notifications,omitempty"`
}

BudgetRecord is a stored budget with its notifications and tags.

type BudgetedAndActualAmounts

type BudgetedAndActualAmounts struct {
	ActualAmount   *Spend      `json:"ActualAmount,omitempty"`
	BudgetedAmount *Spend      `json:"BudgetedAmount,omitempty"`
	TimePeriod     *TimePeriod `json:"TimePeriod,omitempty"`
}

BudgetedAndActualAmounts is one performance-history period.

type CalculatedSpend

type CalculatedSpend struct {
	ForecastedSpend *Spend `json:"ForecastedSpend,omitempty"`
	ActualSpend     Spend  `json:"ActualSpend"`
}

CalculatedSpend is the derived spend of the current period.

type CostTypes

type CostTypes struct {
	IncludeCredit            *bool `json:"IncludeCredit,omitempty"`
	IncludeDiscount          *bool `json:"IncludeDiscount,omitempty"`
	IncludeOtherSubscription *bool `json:"IncludeOtherSubscription,omitempty"`
	IncludeRecurring         *bool `json:"IncludeRecurring,omitempty"`
	IncludeRefund            *bool `json:"IncludeRefund,omitempty"`
	IncludeSubscription      *bool `json:"IncludeSubscription,omitempty"`
	IncludeSupport           *bool `json:"IncludeSupport,omitempty"`
	IncludeTax               *bool `json:"IncludeTax,omitempty"`
	IncludeUpfront           *bool `json:"IncludeUpfront,omitempty"`
	UseAmortized             *bool `json:"UseAmortized,omitempty"`
	UseBlended               *bool `json:"UseBlended,omitempty"`
}

CostTypes selects which charges a budget includes.

type Definition

type Definition struct {
	IamActionDefinition *IamActionDefinition `json:"IamActionDefinition,omitempty"`
	ScpActionDefinition *ScpActionDefinition `json:"ScpActionDefinition,omitempty"`
	SsmActionDefinition *SsmActionDefinition `json:"SsmActionDefinition,omitempty"`
}

Definition holds the type-specific action parameters.

type Delivery

type Delivery struct {
	AccountID   string
	BudgetName  string
	Subject     string
	Message     string
	Subscribers []Subscriber
}

Delivery is one alert to send to subscribers.

type Expression

type Expression struct {
	CostCategories    *ValuesFilter `json:"CostCategories,omitempty"`
	Dimensions        *ValuesFilter `json:"Dimensions,omitempty"`
	Tags              *ValuesFilter `json:"Tags,omitempty"`
	ProductAttributes *ValuesFilter `json:"ProductAttributes,omitempty"`
	Not               *Expression   `json:"Not,omitempty"`
	And               []Expression  `json:"And,omitempty"`
	Or                []Expression  `json:"Or,omitempty"`
}

Expression is a budget filter expression tree.

type Handler

type Handler struct {
	Backend *InMemoryBackend
}

Handler serves the Budgets awsjson1.1 API.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler wraps a backend.

func (*Handler) ChaosOperations

func (h *Handler) ChaosOperations() []string

ChaosOperations lists the fault-injectable operations.

func (*Handler) ChaosRegions

func (h *Handler) ChaosRegions() []string

ChaosRegions lists the regions this handler serves; Budgets is homed in one region.

func (*Handler) ChaosServiceName

func (h *Handler) ChaosServiceName() string

ChaosServiceName returns the lowercase service name for fault rules.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(c *echo.Context) string

ExtractOperation returns the operation name from X-Amz-Target.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(c *echo.Context) string

ExtractResource returns the operation name; the API has no single resource key.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists every routed operation.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns the echo handler.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority returns the routing priority.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset clears all state.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher matches the AWSBudgetServiceGateway X-Amz-Target prefix.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable.

type HealthStatus

type HealthStatus struct {
	LastUpdatedTime *Timestamp `json:"LastUpdatedTime,omitempty"`
	Status          string     `json:"Status,omitempty"`
	StatusReason    string     `json:"StatusReason,omitempty"`
}

HealthStatus reports billing-view health.

type HistoricalOptions

type HistoricalOptions struct {
	BudgetAdjustmentPeriod   int32 `json:"BudgetAdjustmentPeriod"`
	LookBackAvailablePeriods int32 `json:"LookBackAvailablePeriods,omitempty"`
}

HistoricalOptions configures historical auto-adjust.

type IamActionDefinition

type IamActionDefinition struct {
	PolicyArn string   `json:"PolicyArn"`
	Groups    []string `json:"Groups,omitempty"`
	Roles     []string `json:"Roles,omitempty"`
	Users     []string `json:"Users,omitempty"`
}

IamActionDefinition attaches a policy to principals.

type InMemoryBackend

type InMemoryBackend struct {
	// contains filtered or unexported fields
}

InMemoryBackend is the Budgets state; one coarse lock guards every table.

func NewInMemoryBackend

func NewInMemoryBackend(accountID, region string) *InMemoryBackend

NewInMemoryBackend creates an empty backend.

func (*InMemoryBackend) AccountID

func (b *InMemoryBackend) AccountID() string

AccountID returns the default account.

func (*InMemoryBackend) BudgetPerformance

func (b *InMemoryBackend) BudgetPerformance(
	account, name string, tp *TimePeriod, token string, maxResults *int32,
) (*PerformanceHistory, string, error)

BudgetPerformance returns per-period budgeted and actual amounts, newest period last.

func (*InMemoryBackend) CreateBudget

func (b *InMemoryBackend) CreateBudget(
	ctx context.Context, account string, bg Budget, notifs []NotificationWithSubscribers, rtags []ResourceTag,
) error

CreateBudget stores a budget with optional notifications and tags.

func (*InMemoryBackend) CreateBudgetAction

func (b *InMemoryBackend) CreateBudgetAction(
	account, name string, a Action, rtags []ResourceTag,
) (string, error)

CreateBudgetAction stores an action in STANDBY and returns its ID.

func (*InMemoryBackend) CreateNotification

func (b *InMemoryBackend) CreateNotification(
	ctx context.Context, account, name string, n Notification, subs []Subscriber,
) error

CreateNotification adds a notification with its first subscribers.

func (*InMemoryBackend) CreateSubscriber

func (b *InMemoryBackend) CreateSubscriber(account, name string, n Notification, s Subscriber) error

CreateSubscriber adds a recipient to a notification.

func (*InMemoryBackend) DeleteBudget

func (b *InMemoryBackend) DeleteBudget(account, name string) error

DeleteBudget removes a budget with its actions.

func (*InMemoryBackend) DeleteBudgetAction

func (b *InMemoryBackend) DeleteBudgetAction(account, name, id string) (*Action, error)

DeleteBudgetAction removes an action and returns it.

func (*InMemoryBackend) DeleteNotification

func (b *InMemoryBackend) DeleteNotification(account, name string, n Notification) error

DeleteNotification removes a notification and its subscribers.

func (*InMemoryBackend) DeleteSubscriber

func (b *InMemoryBackend) DeleteSubscriber(account, name string, n Notification, s Subscriber) error

DeleteSubscriber removes a recipient; the last one cannot be removed.

func (*InMemoryBackend) EvaluateAll

func (b *InMemoryBackend) EvaluateAll(ctx context.Context)

EvaluateAll evaluates every budget.

func (*InMemoryBackend) ExecuteBudgetAction

func (b *InMemoryBackend) ExecuteBudgetAction(
	ctx context.Context, account, name, id, execType string,
) error

ExecuteBudgetAction drives an action through approve, retry, reverse or reset.

func (*InMemoryBackend) GetAction

func (b *InMemoryBackend) GetAction(ctx context.Context, account, name, id string) (*Action, error)

GetAction returns one action.

func (*InMemoryBackend) GetBudget

func (b *InMemoryBackend) GetBudget(ctx context.Context, account, name string, showFilter bool) (*Budget, error)

GetBudget returns one budget.

func (*InMemoryBackend) ListActionHistories

func (b *InMemoryBackend) ListActionHistories(
	account, name, id string, tp *TimePeriod, token string, maxResults *int32,
) (page.Page[ActionHistory], error)

ListActionHistories pages an action's events, newest first, within an optional window.

func (*InMemoryBackend) ListActionsForAccount

func (b *InMemoryBackend) ListActionsForAccount(
	ctx context.Context, account, token string, maxResults *int32,
) (page.Page[Action], error)

ListActionsForAccount pages every action of an account.

func (*InMemoryBackend) ListActionsForBudget

func (b *InMemoryBackend) ListActionsForBudget(
	ctx context.Context, account, name, token string, maxResults *int32,
) (page.Page[Action], error)

ListActionsForBudget pages a budget's actions.

func (*InMemoryBackend) ListBudgetNotificationsForAccount

func (b *InMemoryBackend) ListBudgetNotificationsForAccount(
	ctx context.Context, account, token string, maxResults *int32,
) (page.Page[BudgetNotificationsForAccount], error)

ListBudgetNotificationsForAccount pages budgets that have notifications.

func (*InMemoryBackend) ListBudgets

func (b *InMemoryBackend) ListBudgets(
	ctx context.Context, account, token string, maxResults *int32, showFilter bool,
) (page.Page[Budget], error)

ListBudgets pages an account's budgets by name.

func (*InMemoryBackend) ListNotifications

func (b *InMemoryBackend) ListNotifications(
	ctx context.Context, account, name, token string, maxResults *int32,
) (page.Page[Notification], error)

ListNotifications pages a budget's notifications.

func (*InMemoryBackend) ListSubscribers

func (b *InMemoryBackend) ListSubscribers(
	account, name string, n Notification, token string, maxResults *int32,
) (page.Page[Subscriber], error)

ListSubscribers pages a notification's recipients.

func (*InMemoryBackend) ListTagsForResource

func (b *InMemoryBackend) ListTagsForResource(resource string) (map[string]string, error)

ListTagsForResource returns a resource's tags.

func (*InMemoryBackend) Region

func (b *InMemoryBackend) Region() string

Region returns the home region.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset clears every table.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads a snapshot; an incompatible version is discarded.

func (*InMemoryBackend) SetActionExecutor

func (b *InMemoryBackend) SetActionExecutor(e ActionExecutor)

SetActionExecutor wires action execution.

func (*InMemoryBackend) SetNotifier

func (b *InMemoryBackend) SetNotifier(n Notifier)

SetNotifier wires alert delivery.

func (*InMemoryBackend) SetSpendSource

func (b *InMemoryBackend) SetSpendSource(s SpendSource)

SetSpendSource wires the cost data used for CalculatedSpend and alerting.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises the backend state.

func (*InMemoryBackend) StartEvaluator

func (b *InMemoryBackend) StartEvaluator(ctx context.Context, interval time.Duration)

StartEvaluator re-evaluates every budget's notifications and actions each interval until ctx ends.

func (*InMemoryBackend) TagResource

func (b *InMemoryBackend) TagResource(resource string, add []ResourceTag) error

TagResource adds or replaces tags on a budget or action.

func (*InMemoryBackend) UntagResource

func (b *InMemoryBackend) UntagResource(resource string, keys []string) error

UntagResource removes tags by key.

func (*InMemoryBackend) UpdateBudget

func (b *InMemoryBackend) UpdateBudget(ctx context.Context, account string, bg Budget) error

UpdateBudget replaces a budget definition, keeping its notifications and tags.

func (*InMemoryBackend) UpdateBudgetAction

func (b *InMemoryBackend) UpdateBudgetAction(
	account, name, id string, p ActionPatch,
) (*Action, *Action, error)

UpdateBudgetAction patches an action and returns its old and new forms.

func (*InMemoryBackend) UpdateNotification

func (b *InMemoryBackend) UpdateNotification(
	ctx context.Context, account, name string, oldN, newN Notification,
) error

UpdateNotification replaces a notification's definition, keeping its subscribers.

func (*InMemoryBackend) UpdateSubscriber

func (b *InMemoryBackend) UpdateSubscriber(account, name string, n Notification, oldS, newS Subscriber) error

UpdateSubscriber replaces a recipient.

type Notification

type Notification struct {
	ComparisonOperator string  `json:"ComparisonOperator"`
	NotificationState  string  `json:"NotificationState,omitempty"`
	NotificationType   string  `json:"NotificationType"`
	ThresholdType      string  `json:"ThresholdType,omitempty"`
	Threshold          float64 `json:"Threshold"`
}

Notification is a budget alert rule.

type NotificationRecord

type NotificationRecord struct {
	Notification Notification `json:"notification"`
	Subscribers  []Subscriber `json:"subscribers"`
}

NotificationRecord is a notification and its subscribers.

type NotificationWithSubscribers

type NotificationWithSubscribers struct {
	Notification Notification `json:"Notification"`
	Subscribers  []Subscriber `json:"Subscribers"`
}

NotificationWithSubscribers pairs a notification with its recipients.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, d Delivery) error
}

Notifier delivers alerts to SNS topics and email addresses.

type PerformanceHistory

type PerformanceHistory struct {
	CostFilters                  map[string][]string        `json:"CostFilters,omitempty"`
	CostTypes                    *CostTypes                 `json:"CostTypes,omitempty"`
	FilterExpression             *Expression                `json:"FilterExpression,omitempty"`
	BillingViewArn               string                     `json:"BillingViewArn,omitempty"`
	BudgetName                   string                     `json:"BudgetName"`
	BudgetType                   string                     `json:"BudgetType"`
	TimeUnit                     string                     `json:"TimeUnit"`
	Metrics                      []string                   `json:"Metrics,omitempty"`
	BudgetedAndActualAmountsList []BudgetedAndActualAmounts `json:"BudgetedAndActualAmountsList"`
}

PerformanceHistory is the DescribeBudgetPerformanceHistory payload.

type Provider

type Provider struct{}

Provider implements service.Provider for AWS Budgets.

func (*Provider) Init

Init builds the backend and starts the notification evaluator.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name.

type ResourceTag

type ResourceTag struct {
	Key   string `json:"Key"`
	Value string `json:"Value"`
}

ResourceTag is a key/value tag.

type ScpActionDefinition

type ScpActionDefinition struct {
	PolicyID  string   `json:"PolicyId"`
	TargetIDs []string `json:"TargetIds"`
}

ScpActionDefinition attaches a service control policy to targets.

type Spend

type Spend struct {
	Amount string `json:"Amount"`
	Unit   string `json:"Unit"`
}

Spend is an amount with a unit.

type SpendSource

type SpendSource interface {
	Spend(start, end time.Time, filters map[string][]string, metric string) (float64, bool)
}

SpendSource supplies spend for a window [start, end). ok is false when no cost data exists.

type SsmActionDefinition

type SsmActionDefinition struct {
	ActionSubType string   `json:"ActionSubType"`
	Region        string   `json:"Region"`
	InstanceIDs   []string `json:"InstanceIds"`
}

SsmActionDefinition runs a Systems Manager document against instances.

type Subscriber

type Subscriber struct {
	Address          string `json:"Address"`
	SubscriptionType string `json:"SubscriptionType"`
}

Subscriber is an alert recipient.

type TimePeriod

type TimePeriod struct {
	Start *Timestamp `json:"Start,omitempty"`
	End   *Timestamp `json:"End,omitempty"`
}

TimePeriod is a half-open budget window.

type Timestamp

type Timestamp struct{ time.Time }

Timestamp marshals as epoch seconds.

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON renders the epoch-seconds number the SDK expects.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) error

UnmarshalJSON reads an epoch-seconds number.

type ValuesFilter

type ValuesFilter struct {
	Key          string   `json:"Key,omitempty"`
	Values       []string `json:"Values,omitempty"`
	MatchOptions []string `json:"MatchOptions,omitempty"`
}

ValuesFilter is the shared shape of CostCategories, Dimensions, Tags and ProductAttributes clauses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL