Account management
The Account service gives local AWS clients a small AWS-compatible account-management surface. It accepts REST JSON requests for alternate contacts, keeps each contact in the account that owns it, and applies organization rules when an authorized caller manages another account.
Request handling
The service uses the shared request path to turn an AWS-signed HTTP request into an account-scoped operation. The request path resolves the caller account before the Account service reads or writes state.
Request context
src/…/AccountContextFilter.java is the first meaningful boundary for Account requests. It resolves the account from the AWS credential, an IAM or temporary session lookup, or the configured default account, then stores it in RequestContext for the service handler.
The Account service uses the resolved account as the caller account. A request does not need an AccountId field to manage its own contact.
References: src/…/AccountContextFilter.java• L13-23 src/…/AccountContextFilter.java• L52-91 src/…/RequestContext.java• L5-29
REST JSON boundary
The Account service is registered as an enabled REST JSON service. Its two operations use POST requests at the action paths /putAlternateContact and /getAlternateContact, with JSON request and response bodies.
The controller passes the request body and resolved caller account to the service. A successful put returns an empty JSON object. A successful get returns the contact under the AlternateContact response field.
The request body must contain one complete JSON value. Invalid JSON and trailing JSON produce an AWS-shaped SerializationException response instead of reaching account state handling.
The following diagram shows the request path from the client to stored account state.
flowchart LR
Client[AWS client] --> Context[Account and region context]
Context --> Controller[REST JSON action]
Controller --> Service[Account service]
Service --> Scope{Caller account or target account}
Scope --> Store[Alternate-contact state]
Store --> Response[AWS-shaped JSON response]
References: src/…/ResolvedServiceCatalog.java• L417-419 src/…/AccountController.java• L19-57 src/…/JsonErrorResponseUtils.java• L32-41
Operation surface
The service exposes the account-management operations that the emulator supports. Both operations use the same contact type and account-scope rules, but one changes state and the other reads it.
Alternate-contact operations
PutAlternateContact creates or replaces one alternate contact for an account and contact type. GetAlternateContact reads that contact and returns ResourceNotFoundException when no value has been configured.
The supported contact types are BILLING, OPERATIONS, and SECURITY. The put request requires these fields:
| Field | Purpose |
|---|---|
AlternateContactType | Selects the contact slot |
EmailAddress | Contact email address |
Name | Contact name |
PhoneNumber | Contact phone number |
Title | Contact role or title |
The optional AccountId field changes the target account. If it is absent, the caller account is the target. If it is present, it must be a string containing a 12-digit account ID.
References: src/…/AccountController.java• L34-47 src/…/AccountService.java• L38-70 src/…/AlternateContact.java• L9-31
Contact validation
The service validates the contact as an AWS API request before it changes stored state. It accepts non-empty values within the service's field limits and checks that the email and phone values match the expected basic formats.
| Value | Accepted rule |
|---|---|
AlternateContactType | One of the three supported types; up to 32 characters |
EmailAddress | 1 to 254 characters and an email-shaped value |
Name | 1 to 64 characters |
PhoneNumber | 1 to 25 characters and a phone-shaped value |
Title | 1 to 50 characters |
An update uses the same operation as creation. A later put for the same account and contact type becomes the value returned by a later get.
References: src/…/AccountService.java• L21-27 src/…/AccountService.java• L40-47 src/…/AccountService.java• L110-141
Alternate-contact state
Alternate-contact state is scoped by both AWS account and contact type. This gives each account one independent slot for each supported type and prevents a contact in one account from appearing in another account's ordinary get request.
State identity
The logical state key is the pair (account ID, alternate contact type). A put writes the complete contact to that key, so the stored value contains the type and its four contact details but does not carry a separate resource ID.
The service uses the account-aware storage layer for this state. That layer selects the request account during normal request handling and supports an explicit account when the service performs an authorized cross-account operation.
References: src/…/AccountService.java• L28-35 src/…/AccountService.java• L38-56 src/…/AccountAwareStorageBackend.java• L17-31 src/…/AccountAwareStorageBackend.java• L315-326
State persistence
The service creates its state through the shared storage factory under the Account service namespace. The selected emulator storage mode therefore controls whether contacts are held in memory or kept in the configured persistent store.
Resetting the Account service clears all alternate-contact state. A missing contact after a reset has the same read result as a contact that was never configured.
References: src/…/AccountService.java• L31-35 src/…/AccountService.java• L105-108 src/…/AccountAwareStorageBackend.java• L57-121
Target account access
An AccountId in a request asks the Account service to act on another account rather than changing the caller identity. The service permits this only when the caller and target accounts satisfy the local Organizations model for Account Management trusted access.
Organization controls
Cross-account access requires all of the following conditions:
- The caller and target accounts are known to the same organization.
- The organization uses the
ALLfeature set. - The organization enables trusted access for
account.amazonaws.com. - The caller is the organization management account or a delegated Account Management administrator.
The management account cannot pass its own account ID as an explicit target. A member account can manage its own contact without these cross-account checks by omitting AccountId.
References: src/…/AccountService.java• L58-103 src/…/AccountService.java• L22-26
Targeted state flow
The service first resolves the target account and checks access. Only after those checks pass does it validate the contact and write or read the target account's contact slot.
This ordering keeps an unauthorized caller from using a valid contact body to change another account's state. It also keeps the state owner separate from the account that signed the request.
References: src/…/AccountService.java• L38-56 src/…/AccountService.java• L72-102
Error behavior
The service returns AWS-shaped errors that identify whether the request was malformed, invalid, unauthorized, or missing state. The shared response layer carries the service error code and HTTP status to the REST client.
Client errors
The main client-visible failures are:
| Condition | Error | HTTP status |
|---|---|---|
| Invalid JSON or trailing JSON | SerializationException | 400 |
Non-string AccountId | SerializationException | 400 |
| Invalid account ID or contact fields | ValidationException | 400 |
| Failed target-account access checks | AccessDeniedException | 403 |
| Contact slot has no stored value | ResourceNotFoundException | 404 |
The service does not create provider-side throttling or internal failures as normal account-management behavior. Such failures require a separate triggering condition in the emulator.
References: src/…/AccountService.java• L50-55 src/…/AccountService.java• L63-100 src/…/JsonErrorResponseUtils.java• L17-55
Service boundaries
The Account service manages alternate contacts only. It does not create AWS accounts, manage billing plans, or replace the organization service that supplies membership and trusted-access data for targeted requests.
Service availability
The service is enabled by default through FLOCI_SERVICES_ACCOUNT_ENABLED. Disabling it removes the Account service from normal request dispatch, while the shared request and storage systems remain used by other services.
The request protocol and account resolution rules are shared with the rest of the emulator. See Request routing and protocols for that common path and Storage backend for account-scoped persistence.
References: src/…/EmulatorConfig.java• L751-754 src/…/ResolvedServiceCatalog.java• L417-419
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the REST action paths, JSON field names, and response wrapper aligned with the AWS Account client contract.
- Keep the account target checks aligned with the organization trusted-service principal and delegated-administrator model.
- Keep contact validation and stored key identity aligned so a contact remains unique by account and contact type.
- Keep the Account service storage namespace aligned with its configured persistence and reset behavior.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
The request uses a numeric or malformed AccountId | The service rejects the request or may target the wrong scope if validation is bypassed | Require a textual 12-digit account ID before organization lookup |
| A caller requests another account without trusted Account Management access | The request receives AccessDeniedException and must not read or write target state | Check organization membership, feature set, trusted access, and caller role before storage access |
| A put changes the storage key shape without preserving account and contact type | Contacts can overwrite each other or leak between accounts | Treat account ID and contact type as the state identity |
| A get uses a contact type outside the supported set | The service returns ValidationException instead of a missing-resource result | Validate the type before reading storage |
| The controller accepts trailing JSON | A malformed client body can be processed as a valid request | Parse with trailing-token checks and return SerializationException |
Key files
| File | Why to read it |
|---|---|
| src/…/AccountController.java | Shows the REST JSON action boundary and response shapes |
| src/…/AccountService.java | Shows operation scope, validation, organization access, and state lifecycle |
| src/…/AlternateContact.java | Defines the contact data returned by the service |
| src/…/AccountContextFilter.java | Shows how the caller account reaches service requests |
| src/…/AccountAwareStorageBackend.java | Explains the account partition used for contact state |
| src/…/ResolvedServiceCatalog.java | Shows the Account service protocol and registration |
| src/…/AccountAlternateContactIntegrationTest.java | Demonstrates end-to-end REST behavior and AWS-shaped client errors |