diff --git a/README.md b/README.md
index 17c4aefd79..bb3a61122e 100644
--- a/README.md
+++ b/README.md
@@ -239,7 +239,7 @@ Floci supports local emulation for application services, data services, eventing
| Databases and caching | RDS, RDS Data API, Neptune, DocumentDB, MemoryDB, ElastiCache |
| Messaging and transfer | SES, Kinesis, MSK, Amazon MQ, Transfer Family, IoT Core, Amazon Connect |
| Security and governance | AWS Network Firewall, AWS RAM, Service Quotas, WAF v2, GuardDuty, CloudTrail, CloudFront, Resource Groups Tagging API, Resource Explorer 2, CloudHSM v2, Organizations, AWS Account Management, IAM Access Analyzer, IAM Identity Center (SSO Admin), Identity Store, Amazon Macie, Control Tower, Service Catalog |
-| Cost and billing | Pricing, Cost Explorer, Cost and Usage Reports, BCM Data Exports |
+| Cost and billing | AWS Budgets, Pricing, Cost Explorer, Cost and Usage Reports, BCM Data Exports |
| Resilience, backup, and config | AWS FIS, AWS Backup, AWS Config, AppConfig, AppConfigData, CloudFormation, Cloud Control API |
For operation-level compatibility, see the [Services Overview](https://floci.io/floci/services/).
diff --git a/compatibility-tests/sdk-test-java/pom.xml b/compatibility-tests/sdk-test-java/pom.xml
index a3b71d50b9..10aef8febb 100644
--- a/compatibility-tests/sdk-test-java/pom.xml
+++ b/compatibility-tests/sdk-test-java/pom.xml
@@ -244,6 +244,10 @@
software.amazon.awssdk
identitystore
+
+ software.amazon.awssdk
+ budgets
+
software.amazon.awssdk
diff --git a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
index 7f3820d2f0..36184b46cc 100644
--- a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
+++ b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
@@ -34,6 +34,7 @@ import software.amazon.awssdk.services.fis.FisClient;
import software.amazon.awssdk.services.organizations.OrganizationsClient;
import software.amazon.awssdk.services.ssoadmin.SsoAdminClient;
import software.amazon.awssdk.services.identitystore.IdentitystoreClient;
+import software.amazon.awssdk.services.budgets.BudgetsClient;
import software.amazon.awssdk.services.macie2.Macie2Client;
import software.amazon.awssdk.services.rum.RumClient;
import software.amazon.awssdk.services.resourceexplorer2.ResourceExplorer2Client;
@@ -312,6 +313,22 @@ public final class TestFixtures {
.build();
}
+ public static BudgetsClient budgetsClient() {
+ return BudgetsClient.builder()
+ .endpointOverride(ENDPOINT)
+ .region(REGION)
+ .credentialsProvider(CREDENTIALS)
+ .build();
+ }
+
+ public static BudgetsClient budgetsClient(String accountId) {
+ return BudgetsClient.builder()
+ .endpointOverride(ENDPOINT)
+ .region(REGION)
+ .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accountId, "test")))
+ .build();
+ }
+
public static Macie2Client macie2Client() {
return macie2Client("test");
}
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/BudgetsTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/BudgetsTest.java
new file mode 100644
index 0000000000..f55527838d
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/BudgetsTest.java
@@ -0,0 +1,138 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.budgets.BudgetsClient;
+import software.amazon.awssdk.services.budgets.model.*;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class BudgetsTest {
+ private static final String ACCOUNT_ID = "000000000000";
+
+ @Test
+ void completeBudgetLifecycle() {
+ String budgetName = TestFixtures.uniqueName("budget");
+ Notification notification = Notification.builder()
+ .notificationType(NotificationType.ACTUAL)
+ .comparisonOperator(ComparisonOperator.GREATER_THAN)
+ .threshold(80d)
+ .thresholdType(ThresholdType.PERCENTAGE)
+ .build();
+ Subscriber firstSubscriber = Subscriber.builder()
+ .subscriptionType(SubscriptionType.EMAIL)
+ .address("billing@example.com")
+ .build();
+
+ try (BudgetsClient client = TestFixtures.budgetsClient()) {
+ client.createBudget(CreateBudgetRequest.builder()
+ .accountId(ACCOUNT_ID)
+ .budget(Budget.builder()
+ .budgetName(budgetName)
+ .budgetType(BudgetType.COST)
+ .timeUnit(TimeUnit.MONTHLY)
+ .budgetLimit(Spend.builder().amount(new java.math.BigDecimal("100.00")).unit("USD").build())
+ .build())
+ .notificationsWithSubscribers(NotificationWithSubscribers.builder()
+ .notification(notification)
+ .subscribers(firstSubscriber)
+ .build())
+ .resourceTags(ResourceTag.builder().key("managed_by").value("floci-test").build())
+ .build());
+
+ assertThat(client.describeBudget(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName)).budget().budgetName())
+ .isEqualTo(budgetName);
+ assertThat(client.describeBudgets(b -> b.accountId(ACCOUNT_ID).maxResults(1000)).budgets())
+ .extracting(Budget::budgetName).contains(budgetName);
+ assertThat(client.describeNotificationsForBudget(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName)).notifications())
+ .hasSize(1);
+ assertThat(client.describeSubscribersForNotification(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName).notification(notification)).subscribers())
+ .hasSize(1);
+ assertThat(client.describeBudgetNotificationsForAccount(b -> b.accountId(ACCOUNT_ID)).budgetNotificationsForAccount())
+ .anyMatch(item -> budgetName.equals(item.budgetName()));
+
+ Subscriber second = Subscriber.builder().subscriptionType(SubscriptionType.EMAIL).address("ops@example.com").build();
+ client.createSubscriber(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName).notification(notification).subscriber(second));
+ Subscriber replacement = Subscriber.builder().subscriptionType(SubscriptionType.EMAIL).address("finops@example.com").build();
+ client.updateSubscriber(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName).notification(notification)
+ .oldSubscriber(second).newSubscriber(replacement));
+ client.deleteSubscriber(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName).notification(notification).subscriber(replacement));
+
+ Notification updatedNotification = notification.toBuilder().threshold(90d).build();
+ client.updateNotification(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName)
+ .oldNotification(notification).newNotification(updatedNotification));
+
+ String budgetArn = "arn:aws:budgets::" + ACCOUNT_ID + ":budget/" + budgetName;
+ client.tagResource(b -> b.resourceARN(budgetArn).resourceTags(ResourceTag.builder().key("team").value("platform").build()));
+ assertThat(client.listTagsForResource(b -> b.resourceARN(budgetArn)).resourceTags())
+ .anyMatch(tag -> "team".equals(tag.key()));
+ client.untagResource(b -> b.resourceARN(budgetArn).resourceTagKeys("team"));
+
+ client.updateBudget(b -> b.accountId(ACCOUNT_ID).newBudget(Budget.builder()
+ .budgetName(budgetName).budgetType(BudgetType.COST).timeUnit(TimeUnit.MONTHLY)
+ .budgetLimit(Spend.builder().amount(new java.math.BigDecimal("150.00")).unit("USD").build()).build()));
+ assertThat(client.describeBudgetPerformanceHistory(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName)).budgetPerformanceHistory())
+ .isNotNull();
+
+ CreateBudgetActionResponse createdAction = client.createBudgetAction(CreateBudgetActionRequest.builder()
+ .accountId(ACCOUNT_ID)
+ .budgetName(budgetName)
+ .notificationType(NotificationType.ACTUAL)
+ .actionType(ActionType.APPLY_IAM_POLICY)
+ .actionThreshold(ActionThreshold.builder().actionThresholdType(ThresholdType.PERCENTAGE).actionThresholdValue(100d).build())
+ .definition(Definition.builder().iamActionDefinition(IamActionDefinition.builder()
+ .policyArn("arn:aws:iam::aws:policy/ReadOnlyAccess").users("alice").build()).build())
+ .executionRoleArn("arn:aws:iam::" + ACCOUNT_ID + ":role/BudgetExecutionRole")
+ .approvalModel(ApprovalModel.MANUAL)
+ .subscribers(firstSubscriber)
+ .resourceTags(ResourceTag.builder().key("kind").value("guardrail").build())
+ .build());
+ String actionId = createdAction.actionId();
+ assertThat(actionId).isNotBlank();
+ assertThat(client.describeBudgetAction(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName).actionId(actionId)).action().actionId())
+ .isEqualTo(actionId);
+ assertThat(client.describeBudgetActionsForAccount(b -> b.accountId(ACCOUNT_ID)).actions())
+ .extracting(Action::actionId).contains(actionId);
+ assertThat(client.describeBudgetActionsForBudget(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName)).actions())
+ .extracting(Action::actionId).contains(actionId);
+
+ client.updateBudgetAction(UpdateBudgetActionRequest.builder()
+ .accountId(ACCOUNT_ID).budgetName(budgetName).actionId(actionId)
+ .approvalModel(ApprovalModel.AUTOMATIC).build());
+ client.executeBudgetAction(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName).actionId(actionId)
+ .executionType(ExecutionType.APPROVE_BUDGET_ACTION));
+ Action executed = client.describeBudgetAction(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName).actionId(actionId)).action();
+ assertThat(executed.status()).isEqualTo(ActionStatus.EXECUTION_SUCCESS);
+ List histories = client.describeBudgetActionHistories(
+ b -> b.accountId(ACCOUNT_ID).budgetName(budgetName).actionId(actionId)).actionHistories();
+ assertThat(histories).isNotEmpty();
+ assertThat(histories).anySatisfy(history -> {
+ assertThat(history.eventType()).isEqualTo(EventType.EXECUTE_ACTION);
+ assertThat(history.status()).isEqualTo(ActionStatus.EXECUTION_SUCCESS);
+ });
+
+ String actionArn = budgetArn + "/action/" + actionId;
+ client.tagResource(b -> b.resourceARN(actionArn).resourceTags(ResourceTag.builder().key("action").value("yes").build()));
+ assertThat(client.listTagsForResource(b -> b.resourceARN(actionArn)).resourceTags()).isNotEmpty();
+
+ client.deleteBudgetAction(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName).actionId(actionId));
+ client.deleteNotification(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName).notification(updatedNotification));
+ client.deleteBudget(b -> b.accountId(ACCOUNT_ID).budgetName(budgetName));
+ }
+ }
+ @Test
+ void crossAccountBudgetAccessIsDenied() {
+ String caller = "123456789012";
+ String foreign = "210987654321";
+ try (BudgetsClient client = TestFixtures.budgetsClient(caller)) {
+ assertThatThrownBy(() -> client.describeBudget(b -> b.accountId(foreign).budgetName("foreign")))
+ .isInstanceOf(AccessDeniedException.class);
+ assertThatThrownBy(() -> client.listTagsForResource(b ->
+ b.resourceARN("arn:aws:budgets::" + foreign + ":budget/foreign")))
+ .isInstanceOf(AccessDeniedException.class);
+ }
+ }
+
+}
diff --git a/docs/services/budgets.md b/docs/services/budgets.md
new file mode 100644
index 0000000000..212f38f641
--- /dev/null
+++ b/docs/services/budgets.md
@@ -0,0 +1,60 @@
+# AWS Budgets
+
+**Protocol:** JSON 1.1 (`X-Amz-Target: AWSBudgetServiceGateway.*`)
+
+**Signing name:** `budgets`
+
+Floci emulates the complete AWS Budgets management API surface, including budgets, notifications, subscribers, budget actions, action history, performance history, and resource tags. State is persisted locally and isolated by AWS account.
+
+## Supported Actions
+
+
+| Action | Description |
+| --- | --- |
+| `CreateBudget` | - |
+| `CreateBudgetAction` | - |
+| `CreateNotification` | - |
+| `CreateSubscriber` | - |
+| `DeleteBudget` | - |
+| `DeleteBudgetAction` | - |
+| `DeleteNotification` | - |
+| `DeleteSubscriber` | - |
+| `DescribeBudget` | - |
+| `DescribeBudgetAction` | - |
+| `DescribeBudgetActionHistories` | - |
+| `DescribeBudgetActionsForAccount` | - |
+| `DescribeBudgetActionsForBudget` | - |
+| `DescribeBudgetNotificationsForAccount` | - |
+| `DescribeBudgetPerformanceHistory` | - |
+| `DescribeBudgets` | - |
+| `DescribeNotificationsForBudget` | - |
+| `DescribeSubscribersForNotification` | - |
+| `ExecuteBudgetAction` | - |
+| `ListTagsForResource` | - |
+| `TagResource` | - |
+| `UntagResource` | - |
+| `UpdateBudget` | - |
+| `UpdateBudgetAction` | - |
+| `UpdateNotification` | - |
+| `UpdateSubscriber` | - |
+
+
+## Behavior
+
+Budgets support the AWS budget types and time units, fixed or planned limits, legacy or expression-based filters, notifications and subscribers, and account-scoped listing. Budget actions support IAM, SCP, and SSM definition shapes, approval models, execution status transitions, history, and tags.
+
+Pagination uses the operation-specific AWS limits. `DescribeBudgets` and `DescribeBudgetNotificationsForAccount` allow up to 1000 results, while notification, subscriber, action, action-history, and performance-history listings use their documented lower limits.
+
+`DescribeBudgetPerformanceHistory` returns deterministic local history metadata. Floci does not manufacture provider billing usage, forecasts, or provider-side failures that do not arise from local state.
+
+## AWS-compatible failures
+
+Floci validates account IDs, budget names, budget/filter unions, tags, notification thresholds, subscriber quotas, action definitions, role ownership, action identifiers, and pagination. Deterministic failures use modeled AWS errors such as `InvalidParameterException`, `NotFoundException`, `DuplicateRecordException`, `CreationLimitExceededException`, `ServiceQuotaExceededException`, and `InvalidNextTokenException`.
+
+See the [AWS Budgets API Reference](https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_Operations_AWS_Budgets.html).
+
+## Configuration
+
+| Variable | Default | Description |
+|---|---|---|
+| `FLOCI_SERVICES_BUDGETS_ENABLED` | `true` | Enable or disable AWS Budgets |
diff --git a/docs/services/index.md b/docs/services/index.md
index 3004a12e34..a33e7e7e25 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -97,6 +97,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [AWS Network Firewall](network-firewall.md) | `POST /` + `X-Amz-Target: NetworkFirewall_20201112.*` | JSON 1.0 | 27 |
| [AWS Service Catalog](service-catalog.md) | `POST /` + `X-Amz-Target: AWS242ServiceCatalogService.*` | JSON 1.1 | 89 |
| [Service Quotas](servicequotas.md) | `POST /` + `X-Amz-Target: ServiceQuotasV20190624.*` | JSON 1.1 | 5 |
+| [AWS Budgets](budgets.md) | `POST /` + `X-Amz-Target: AWSBudgetServiceGateway.*` | JSON 1.1 | 26 |
| [AWS RAM](ram.md) | `POST /{operationname}` (lowercase), `DELETE /deleteresourceshare` | REST JSON | 12 |
| [Control Tower](controltower.md) | `/list-landingzones`, `/get-landingzone`, `/create-landingzone`, `/*-baseline*` | REST JSON | 15 |
| [Managed Prometheus (AMP)](managed-prometheus.md) | `/workspaces/*`, `/tags/*` | REST JSON | 8 |
diff --git a/mkdocs.yml b/mkdocs.yml
index 59358e157b..536fc45a67 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -123,6 +123,7 @@ nav:
- IAM Access Analyzer: services/access-analyzer.md
- IAM Identity Center (SSO Admin): services/ssoadmin.md
- Identity Store: services/identitystore.md
+ - AWS Budgets: services/budgets.md
- Amazon Macie: services/macie2.md
- Control Tower: services/controltower.md
- AWS Service Catalog: services/service-catalog.md
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index ee11ef6cd0..eee5ceddd6 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -714,6 +714,7 @@ public interface EmulatorConfig {
AccountServiceConfig account();
AccessAnalyzerServiceConfig accessanalyzer();
IdentityStoreServiceConfig identitystore();
+ BudgetsServiceConfig budgets();
ServiceQuotasServiceConfig servicequotas();
RamServiceConfig ram();
ControlTowerServiceConfig controltower();
@@ -762,6 +763,11 @@ public interface EmulatorConfig {
boolean enabled();
}
+ interface BudgetsServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+ }
+
interface ApsServiceConfig {
@WithDefault("true")
boolean enabled();
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
index c25a2abf75..e9515df300 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
@@ -25,6 +25,7 @@ import io.github.hectorvent.floci.services.applicationautoscaling.ApplicationAut
import io.github.hectorvent.floci.services.cloudcontrol.CloudControlJsonHandler;
import io.github.hectorvent.floci.services.ssoadmin.SsoAdminJsonHandler;
import io.github.hectorvent.floci.services.identitystore.IdentityStoreJsonHandler;
+import io.github.hectorvent.floci.services.budgets.BudgetsJsonHandler;
import io.github.hectorvent.floci.services.configservice.ConfigServiceJsonHandler;
import io.github.hectorvent.floci.services.cur.CurJsonHandler;
import io.github.hectorvent.floci.services.pricing.PricingJsonHandler;
@@ -126,6 +127,7 @@ public class AwsJson11Controller {
private final OrganizationsJsonHandler organizationsJsonHandler;
private final SsoAdminJsonHandler ssoAdminJsonHandler;
private final IdentityStoreJsonHandler identityStoreJsonHandler;
+ private final BudgetsJsonHandler budgetsJsonHandler;
private final ServiceQuotasJsonHandler serviceQuotasJsonHandler;
@Inject
@@ -174,6 +176,7 @@ public class AwsJson11Controller {
OrganizationsJsonHandler organizationsJsonHandler,
SsoAdminJsonHandler ssoAdminJsonHandler,
IdentityStoreJsonHandler identityStoreJsonHandler,
+ BudgetsJsonHandler budgetsJsonHandler,
ServiceQuotasJsonHandler serviceQuotasJsonHandler) {
this.objectMapper = objectMapper;
this.strictBodyReader = objectMapper.reader().with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
@@ -226,6 +229,7 @@ public class AwsJson11Controller {
this.organizationsJsonHandler = organizationsJsonHandler;
this.ssoAdminJsonHandler = ssoAdminJsonHandler;
this.identityStoreJsonHandler = identityStoreJsonHandler;
+ this.budgetsJsonHandler = budgetsJsonHandler;
this.serviceQuotasJsonHandler = serviceQuotasJsonHandler;
}
@@ -314,6 +318,7 @@ public class AwsJson11Controller {
organizationsJsonHandler.handle(action, request, regionResolver.getAccountId());
case "sso" -> ssoAdminJsonHandler.handle(action, request, regionResolver.getAccountId());
case "identitystore" -> identityStoreJsonHandler.handle(action, request);
+ case "budgets" -> budgetsJsonHandler.handle(action, request, regionResolver.getAccountId());
case "servicequotas" -> serviceQuotasJsonHandler.handle(
action, request, region, regionResolver.getAccountId());
default -> null;
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
index 37b44de05e..fd1a980dab 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
@@ -423,6 +423,9 @@ public class ResolvedServiceCatalog {
descriptor("identitystore", "identitystore", config.services().identitystore().enabled(), true,
"identitystore", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON), Set.of("AWSIdentityStore."), Set.of("identitystore"), Set.of(), Set.of()),
+ descriptor("budgets", "budgets", config.services().budgets().enabled(), true,
+ "budgets", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
+ protocols(ServiceProtocol.JSON), Set.of("AWSBudgetServiceGateway."), Set.of("budgets"), Set.of(), Set.of()),
descriptor("autoscaling", "autoscaling", config.services().autoscaling().enabled(), true,
"autoscaling", config.storage().mode(), 5000L, AwsNamespaces.AUTOSCALING, ServiceProtocol.QUERY,
protocols(ServiceProtocol.QUERY),
diff --git a/src/main/java/io/github/hectorvent/floci/services/budgets/BudgetsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/budgets/BudgetsJsonHandler.java
new file mode 100644
index 0000000000..e209dc652e
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/budgets/BudgetsJsonHandler.java
@@ -0,0 +1,130 @@
+package io.github.hectorvent.floci.services.budgets;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.services.budgets.model.BudgetActionRecord;
+import io.github.hectorvent.floci.services.budgets.model.BudgetRecord;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Response;
+
+@ApplicationScoped
+public class BudgetsJsonHandler {
+ private final BudgetsService budgetsService;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public BudgetsJsonHandler(BudgetsService budgetsService, ObjectMapper objectMapper) {
+ this.budgetsService = budgetsService;
+ this.objectMapper = objectMapper;
+ }
+
+ public Response handle(String action, JsonNode request, String callerAccountId) {
+ budgetsService.validateCallerScope(request, callerAccountId);
+ return switch (action) {
+ case "CreateBudget" -> emptyAfter(() -> budgetsService.createBudget(request));
+ case "CreateBudgetAction" -> createBudgetAction(request);
+ case "CreateNotification" -> emptyAfter(() -> budgetsService.createNotification(request));
+ case "CreateSubscriber" -> emptyAfter(() -> budgetsService.createSubscriber(request));
+ case "DeleteBudget" -> emptyAfter(() -> budgetsService.deleteBudget(request));
+ case "DeleteBudgetAction" -> deleteBudgetAction(request);
+ case "DeleteNotification" -> emptyAfter(() -> budgetsService.deleteNotification(request));
+ case "DeleteSubscriber" -> emptyAfter(() -> budgetsService.deleteSubscriber(request));
+ case "DescribeBudget" -> describeBudget(request);
+ case "DescribeBudgetAction" -> describeBudgetAction(request);
+ case "DescribeBudgetActionHistories" -> page("ActionHistories", budgetsService.describeBudgetActionHistories(request));
+ case "DescribeBudgetActionsForAccount" -> page("Actions", budgetsService.describeBudgetActionsForAccount(request));
+ case "DescribeBudgetActionsForBudget" -> page("Actions", budgetsService.describeBudgetActionsForBudget(request));
+ case "DescribeBudgetNotificationsForAccount" -> page("BudgetNotificationsForAccount", budgetsService.describeBudgetNotificationsForAccount(request));
+ case "DescribeBudgetPerformanceHistory" -> describeBudgetPerformanceHistory(request);
+ case "DescribeBudgets" -> page("Budgets", budgetsService.describeBudgets(request));
+ case "DescribeNotificationsForBudget" -> page("Notifications", budgetsService.describeNotifications(request));
+ case "DescribeSubscribersForNotification" -> page("Subscribers", budgetsService.describeSubscribers(request));
+ case "ExecuteBudgetAction" -> executeBudgetAction(request);
+ case "ListTagsForResource" -> listTagsForResource(request);
+ case "TagResource" -> emptyAfter(() -> budgetsService.tagResource(request));
+ case "UntagResource" -> emptyAfter(() -> budgetsService.untagResource(request));
+ case "UpdateBudget" -> emptyAfter(() -> budgetsService.updateBudget(request));
+ case "UpdateBudgetAction" -> Response.ok(budgetsService.updateBudgetAction(request)).build();
+ case "UpdateNotification" -> emptyAfter(() -> budgetsService.updateNotification(request));
+ case "UpdateSubscriber" -> emptyAfter(() -> budgetsService.updateSubscriber(request));
+ default -> throw new AwsException("UnknownOperationException", "Operation " + action + " is not supported.", 400);
+ };
+ }
+
+ private Response describeBudget(JsonNode request) {
+ BudgetRecord record = budgetsService.describeBudget(request);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Budget", record.getBudget());
+ return Response.ok(response).build();
+ }
+
+ private Response createBudgetAction(JsonNode request) {
+ BudgetActionRecord record = budgetsService.createBudgetAction(request);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("AccountId", record.getAccountId());
+ response.put("BudgetName", record.getBudgetName());
+ response.put("ActionId", record.getActionId());
+ return Response.ok(response).build();
+ }
+
+
+ private Response deleteBudgetAction(JsonNode request) {
+ BudgetActionRecord record = budgetsService.deleteBudgetAction(request);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("AccountId", record.getAccountId());
+ response.put("BudgetName", record.getBudgetName());
+ response.set("Action", record.getAction());
+ return Response.ok(response).build();
+ }
+
+ private Response describeBudgetAction(JsonNode request) {
+ BudgetActionRecord record = budgetsService.describeBudgetAction(request);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("AccountId", record.getAccountId());
+ response.put("BudgetName", record.getBudgetName());
+ response.set("Action", record.getAction());
+ return Response.ok(response).build();
+ }
+
+ private Response executeBudgetAction(JsonNode request) {
+ BudgetActionRecord record = budgetsService.executeBudgetAction(request);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("AccountId", record.getAccountId());
+ response.put("BudgetName", record.getBudgetName());
+ response.put("ActionId", record.getActionId());
+ response.put("ExecutionType", request.path("ExecutionType").asText());
+ return Response.ok(response).build();
+ }
+
+ private Response describeBudgetPerformanceHistory(JsonNode request) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("BudgetPerformanceHistory", budgetsService.describeBudgetPerformanceHistory(request));
+ return Response.ok(response).build();
+ }
+
+ private Response listTagsForResource(JsonNode request) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ResourceTags", budgetsService.listTagsForResource(request));
+ return Response.ok(response).build();
+ }
+
+ private Response page(String field, PaginatedResult page) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode items = response.putArray(field);
+ page.items().forEach(items::add);
+ if (page.nextToken() != null) {
+ response.put("NextToken", page.nextToken());
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response emptyAfter(Runnable action) {
+ action.run();
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/budgets/BudgetsService.java b/src/main/java/io/github/hectorvent/floci/services/budgets/BudgetsService.java
new file mode 100644
index 0000000000..64d89e5626
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/budgets/BudgetsService.java
@@ -0,0 +1,944 @@
+package io.github.hectorvent.floci.services.budgets;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.Pagination;
+import io.github.hectorvent.floci.core.common.Resettable;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.budgets.model.BudgetActionRecord;
+import io.github.hectorvent.floci.services.budgets.model.BudgetNotification;
+import io.github.hectorvent.floci.services.budgets.model.BudgetRecord;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.regex.Pattern;
+
+@ApplicationScoped
+public class BudgetsService implements Resettable {
+ private static final Pattern ACCOUNT_ID = Pattern.compile("\\d{12}");
+ private static final Pattern ACTION_ID = Pattern.compile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$");
+ private static final Pattern IAM_POLICY_ARN = Pattern.compile("^arn:aws(?:-eusc|-cn|-us-gov|-iso|-iso-[a-z])?:iam::(?:\\d{12}|aws):policy/.+$");
+ private static final Pattern SCP_POLICY_ID = Pattern.compile("^p-[0-9a-zA-Z_]{8,128}$");
+ private static final Pattern SCP_TARGET_ID = Pattern.compile("^(?:ou-[0-9a-z]{4,32}-[a-z0-9]{8,32}|\\d{12})$");
+ private static final Pattern SSM_INSTANCE_ID = Pattern.compile("^(?:i-(?:\\w{8}|\\w{17})|[a-zA-Z](?:[\\w-]{0,61}\\w)?)$");
+ private static final Pattern AWS_REGION = Pattern.compile("^\\w{2,4}-\\w+(?:-\\w+)?-\\d$");
+ private static final Pattern BUDGET_NAME = Pattern.compile("^(?![^:\\\\]*/action/|(?i).*.*)[^:\\\\]+$");
+ private static final Set BUDGET_TYPES = Set.of("USAGE", "COST", "RI_UTILIZATION", "RI_COVERAGE",
+ "SAVINGS_PLANS_UTILIZATION", "SAVINGS_PLANS_COVERAGE");
+ private static final Set TIME_UNITS = Set.of("DAILY", "MONTHLY", "QUARTERLY", "ANNUALLY", "CUSTOM");
+ private static final Set COMPARISONS = Set.of("GREATER_THAN", "LESS_THAN", "EQUAL_TO");
+ private static final Set NOTIFICATION_TYPES = Set.of("ACTUAL", "FORECASTED");
+ private static final Set THRESHOLD_TYPES = Set.of("PERCENTAGE", "ABSOLUTE_VALUE");
+ private static final Set ACTION_TYPES = Set.of("APPLY_IAM_POLICY", "APPLY_SCP_POLICY", "RUN_SSM_DOCUMENTS");
+ private static final Set APPROVAL_MODELS = Set.of("AUTOMATIC", "MANUAL");
+ private static final Set ACTION_THRESHOLD_TYPES = Set.of("PERCENTAGE", "ABSOLUTE_VALUE");
+ private static final int MAX_NOTIFICATIONS = 10;
+ private static final int MAX_EMAIL_SUBSCRIBERS = 10;
+
+ private final AccountAwareStorageBackend budgets;
+ private final AccountAwareStorageBackend actions;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public BudgetsService(StorageFactory storageFactory, ObjectMapper objectMapper) {
+ this(
+ storageFactory.create("budgets", "budgets.json", new TypeReference