EC2 compute and networking
Floci provides an EC2-shaped control plane for compute, images, storage, and VPC networking. It keeps AWS-style resource state while using Docker-backed guests and networks when available, so clients can inspect resources and run local workloads through one model. For the wider request path, see request routing and protocols. Container services that use the same VPC model are described in container orchestration, and EC2 resource checks can use the IAM and authentication model.
Query interface
The EC2 interface accepts XML Query requests at POST /. The Action value selects the operation. Responses use EC2-style XML envelopes and errors. The surface covers instances, images, EBS, VPC resources, addresses, routes, IPAM, metadata, launch templates, Client VPN, instance types, Instance Connect endpoints, network-interface permissions, and related networking records.
Request dispatch
Ec2QueryHandler is the request boundary. It reads flat and nested Query fields, sends work to the main EC2 service or a focused service, and converts the result to XML. Shared protocol rules cover numbered lists, filters, optional scalar values, tags, request IDs, response envelopes, and operation errors. The dispatch surface includes subnet zone IDs, Client VPN, transit gateways, Instance Connect endpoints, IPAM, and the other compute and network resources described below.
The request path is:
flowchart LR
A[EC2 Query request] --> B[Action selection]
B --> C[Query field parsing]
C --> D[Resource service]
D --> E[EC2 state or guest effect]
E --> F[EC2 XML response]
References: src/…/Ec2QueryHandler.java• L98-399 src/…/Ec2QueryProtocol.java• L17-118
Resource state
EC2 state uses account and region scope where the AWS resource requires it. The state layer can restore resources after a restart. First use of a region creates the normal default VPC topology. Startup also restores address leases, guest networking, port forwards, and attached volume state for live instances.
Create operations that support a ClientToken treat a retry as the same request. A changed request can fail with IdempotentParameterMismatch, while a matching retry returns the earlier resource instead of creating another one. This protects resource creation and CIDR allocation from retries by callers such as CloudFormation.
Resource identifiers have two broad forms. Most new resources use a random EC2-style suffix. Default resources and synthesized service-owned resources use stable identifiers derived from their scope, so reads and related records remain consistent after restart. IAM-aware resource lookup also resolves stored launch-template names and attached network-interface or instance targets to the resource ARN used by authorization.
References: src/…/Ec2Service.java• L293-375 src/…/Ec2ClientTokens.java• L11-39 src/…/Ec2Startup.java• L1-200 src/…/Ec2Ids.java• L7-35 src/…/Ec2StoredResourceArns.java• L11-41
Compute lifecycle
An EC2 instance joins an API record to a guest process. Floci records the instance and its network shape first. It then starts a Docker container when the runtime is available. Lifecycle changes update both the API state and guest reachability.
Instance launch
RunInstances resolves the image, instance type, placement, subnet, security groups, network interface, private address, public-IP choice, metadata options, and optional capacity placement. It creates the instance and root-volume records before starting the guest. A successful guest launch moves the instance from pending to running.
Launch data can include user data, an SSH key, an IAM profile, tags, block-device settings, metadata options, a primary network-interface specification, and launch-template data. A launch-template reference selects a stored version before direct request fields are applied. Security groups must come from one launch location. A launch-time public-IP choice takes precedence over the subnet default.
The image and instance-type catalogs define the supported guest runtime and hardware shape. Captured images keep their source ancestry. Unknown images use the configured default guest. Windows images are not executable in the Linux container runtime. Architecture mismatches fail before launch.
References: src/…/Ec2QueryHandler.java• L794-817 src/…/Ec2Service.java• L4387-4616 src/…/AmiImageResolver.java• L27-67 src/…/Ec2InstanceTypeCatalog.java• L51-106
Instance type catalog
The instance-type catalog is the shared description of supported EC2 shapes. It gives clients a stable view of compute, storage, architecture, usage class, and network limits. The same data supports architecture checks, vCPU quota checks, capacity checks, spot data, and optional Docker resource limits.
References: src/…/Ec2QueryHandler.java• L5108-5163 src/…/Ec2InstanceTypeCatalog.java• L62-106 src/…/Ec2InstanceTypeCatalog.java• L224-259
Instance transitions
Stop, start, reboot, and termination map to guest actions and resource cleanup. Stop removes active forwards and stops the guest. Start restores its network address, metadata registration, forwarding, and attached data volumes. Termination removes the guest and releases its address, temporary credentials, forwarding, attached devices, and capacity membership.
Launch work is asynchronous. A cancelled or timed-out launch is cleaned up so a late Docker result cannot revive it. Without Docker, an unprotected instance can still exist as API-only state and reach running, but it cannot provide guest actions such as SSH, user data, SSM commands, or real block devices. Security-group enforcement instead fails the launch when its protected namespace cannot be prepared.
Protected guests use a helper-owned network namespace. The helper keeps the network identity and policy boundary while the workload starts, stops, and restarts inside that namespace. Systemd-based guests use an isolated control-group view when Docker permits it. Protected guests keep the control-group setup needed for their restricted namespace.
The launch path is:
flowchart LR
A[Instance record] --> B[Pending]
B --> C[Resolve image and network]
C --> D[Start Docker guest]
D --> E[Register metadata and reachability]
E --> F[Running]
F --> G[Stop or reboot]
F --> H[Terminate and release resources]
G --> E
References: src/…/Ec2ContainerManager.java• L456-655 src/…/Ec2ContainerManager.java• L886-1055 src/…/Ec2ContainerManager.java• L1120-1254 src/…/Instance.java• L121-141
Terminated instance retention
Termination changes the instance to terminated but keeps its record visible for about one hour. A scheduled sweep then releases any remaining volume or interface dependencies, removes tags, and deletes the record. This keeps recent termination results available without leaving old resources in the normal instance view forever.
References: src/…/Ec2TerminatedInstanceScheduler.java• L9-17 src/…/Ec2Service.java• L5473-5541 src/…/Ec2Service.java• L5843-5899 src/…/Instance.java• L132-141
Network interface lifecycle
A network interface is a separately addressable resource. It can exist before an instance, attach later, or act as the primary interface at launch. Its subnet, private addresses, IPv6 addresses, security groups, tags, and attachment state remain visible through EC2 reads.
Primary interfaces embedded in instance records and standalone interfaces share the same address and attachment rules. Service-owned endpoint interfaces are synthesized from their endpoint and subnet scope with stable IDs. This keeps endpoint, network-interface, and flow-log views aligned without making every service interface a separate stored resource.
Explicit private addresses must be valid for the subnet and free in the relevant account and VPC state. Address comparisons use canonical IPv4 and IPv6 values. This prevents equivalent text forms from claiming the same address twice.
References: src/…/Ec2Service.java• L4500-4541 src/…/Ec2Service.java• L7586-7771 src/…/Ec2Service.java• L16747-16872 src/…/Ec2Ids.java• L25-35 src/…/InstanceNetworkInterface.java• L11-79 src/…/NetworkInterface.java• L11-44
Network interface permissions
Network-interface permissions model an owner granting another account the right to use an interface. The current control-plane grant is INSTANCE-ATTACH; it is stored on the standalone interface and can be created or listed by the owning account. The grant is visible as granted and does not yet make a later attachment consume or enforce the permission.
The service accepts account-scoped lookup, documented filters, and pagination for these records. Duplicate grants for the same account and permission return the existing grant. EIP association grants and service principals are rejected as unsupported.
References: src/…/Ec2Service.java• L17478-17639 src/…/Ec2QueryHandler.java• L353-364 src/…/Ec2QueryHandler.java• L5690-5723 src/…/NetworkInterfacePermission.java• L6-50
Images and launch configuration
Images and launch templates let clients reuse guest software and launch choices. The image view combines catalog entries with images registered during a test run. Templates retain versioned launch data for later requests.
Image lifecycle
DescribeImages exposes catalog and registered images. CreateImage captures the source instance's image ancestry and block-device shape. It creates an AMI-shaped record and related snapshot-shaped records. A captured Docker image becomes the preferred guest for later launches. Deregistering an image prevents new launches but does not remove it from existing instances.
Unknown image identifiers can still resolve to the configured default guest. The API image identity and the software inside the guest can therefore differ. A catalog image can also carry its guest runtime, cloud-init behavior, and CPU architecture so launch checks and guest startup use one image description.
References: src/…/AmiImageResolver.java• L27-67 src/…/Ec2ImageCatalog.java• L58-117 src/…/Ec2Service.java• L4402-4421 src/…/Ec2QueryHandler.java• L4082-4250
Public-access controls
Account-level public-access controls govern whether new AMI or snapshot sharing is allowed in a region. Image and snapshot controls are separate and persist across restarts. Image sharing accepts block-new-sharing. Snapshot sharing accepts block-new-sharing or block-all-sharing.
References: src/…/Ec2BlockPublicAccessService.java• L15-29 src/…/Ec2BlockPublicAccessService.java• L72-105
Launch template versions
A launch template stores versioned launch data. A new version can start empty or inherit an explicit source version, then replace fields in the request. $Latest and $Default resolve to stored versions. Direct launch fields override template values when both are supplied. Version descriptions stay attached to their version. The service validates the stored launch shape and protects the default and last remaining versions from deletion. Deleted version numbers are not reused, so version history stays monotonic across deletion and restart.
Launch-template data can select an instance type or instance requirements, but not both. It can also define network interfaces, block devices, metadata, IAM profile data, tags, market options, and capacity preferences. A template that stores an IAM profile name resolves that profile when a launch uses the template.
Name lookup is stable for one request. IAM evaluation and the later EC2 operation use the same name-to-ID result, including the case where the name was absent at evaluation time. Stored-resource lookup exposes the resolved launch-template ARN to callers that need an ID-based authorization target.
References: src/…/Ec2Service.java• L10416-10465 src/…/Ec2Service.java• L10590-10629 src/…/Ec2LaunchTemplateSelections.java• L9-28 src/…/Ec2StoredResourceArns.java• L10-30 src/…/LaunchTemplate.java• L22-117
EBS volumes
EBS gives the EC2 API a persistent block-storage model. The API record works without a guest. Optional Docker support maps volume storage into a running container as a device.
Volume lifecycle
CreateVolume records size, type, encryption, performance, snapshot, zone, and tags. A volume can attach only to an instance in the same Availability Zone. Attach and detach update both the volume state and attachment record. Deletion fails while an attachment remains.
Create-volume retries use the client token and the request shape saved with the first call. A matching retry returns the original volume. A changed request with the same token fails instead of silently creating a different volume.
When block-device support is active, the volume has persistent backing storage. Attach maps it into the guest. Detach removes the mapping. Restart restores data-volume mappings. If block-device support is not available, the API attachment can still exist as metadata without a guest device.
References: src/…/Ec2Service.java• L10072-10108 src/…/Ec2Service.java• L10229-10474 src/…/Ec2VolumeBlockDeviceManager.java• L72-119 src/…/Ec2VolumeBlockDeviceManager.java• L267-377 src/…/Volume.java• L14-35
Encryption defaults
EBS encryption defaults are region-scoped account settings. A new volume can inherit the setting when the request does not choose encryption. The default KMS key is the AWS-managed alias/aws/ebs value until the account selects another key. These settings describe volume creation behavior and persist independently of individual volume attachments.
References: src/…/Ec2EbsEncryptionService.java• L13-21 src/…/Ec2EbsEncryptionService.java• L47-91 src/…/Ec2QueryHandler.java• L684-718
VPC networking
The VPC model gives clients the relationships expected by AWS tools. VPCs contain subnets. Subnets use route tables and network ACLs. Instances use interfaces and security groups. These resources define the control-plane topology. When VPC networking is enabled, Floci also creates real same-VPC container reachability.
VPC resource relationships
The service models VPC and subnet CIDRs, DHCP options, interfaces, security groups, network ACLs, gateways, endpoints, prefix lists, flow logs, peering, and transit gateways. A new VPC receives default security-group, route-table, and network-ACL resources. VPCs and subnets cannot be deleted while registered consumers depend on them. Instance Connect endpoints add a modeled access endpoint with subnet and security-group relationships.
Subnets expose both an Availability Zone name and a stable Availability Zone ID. A create request can use either form. If both are present, they must identify the same zone. The service publishes three modeled zones per region and rejects zone IDs outside that set. The subnet also reports the current count of assignable IPv4 addresses, so subnet reads reflect address use by instances and other VPC consumers.
Interface endpoints expose service-owned interface views with private addresses, security groups, DNS entries, and stable IDs. Gateway endpoints have no interface view. These records describe AWS topology. They do not all become Docker packet rules.
References: src/…/Ec2QueryHandler.java• L139-250 src/…/Ec2QueryHandler.java• L3568-3645 src/…/Ec2Service.java• L7586-7810 src/…/Ec2Service.java• L8097-8204 src/…/Subnet.java• L14-67 src/…/Ec2Service.java• L8251-8295 src/…/VpcDependencyProvider.java• L3-16
Client VPN endpoints
Client VPN provides an EC2-shaped control-plane model for remote access to VPC networks. It stores endpoints, target subnet associations, authorization rules, routes, security groups, and exported client configuration. It does not run a VPN server, so clients cannot establish a real VPN connection.
An endpoint starts in pending-associate and becomes available after it has a target network. Associations must use subnets in the endpoint VPC and only one subnet per Availability Zone. Associations add a modeled VPC route and block deletion of the subnet or VPC until removal. Endpoint creation and target-network association support client-token replay.
References: src/…/Ec2ClientVpnService.java• L34-44 src/…/Ec2ClientVpnService.java• L86-150 src/…/Ec2ClientVpnService.java• L252-319 src/…/Ec2ClientVpnService.java• L530-546
DHCP options
DHCP options describe resolver, domain, time, and related settings associated with a VPC. DNS options can mix AmazonProvidedDNS with literal IPv4 or IPv6 addresses within the per-family limits. The options set is a control-plane resource. Associating it does not reconfigure an already running Docker guest.
References: src/…/DhcpConfiguration.java• L9-25 src/…/Ec2Service.java• L5900-6070
Docker VPC networks
VpcNetworkManager maps one VPC to one Docker network rather than creating one network per subnet. It keeps subnet address slices inside that shared VPC network. This preserves same-VPC reachability between containers in different subnets.
Declared private CIDRs are used when they are valid and available. Missing, malformed, non-private, or conflicting ranges use a configured private fallback and produce a warning. A subnet without a usable Docker-backed range keeps its API address model but does not receive a Docker private address.
Route tables, network ACLs, NAT, peering, transit gateways, and egress-only gateways remain API records. They do not program packets on this Docker network. Network isolation between VPCs also depends on the Docker daemon. Startup reconciliation removes only networks owned by this Floci deployment.
The materialized network flow is:
flowchart LR
A[VPC and subnet CIDRs] --> B[Effective private ranges]
B --> C[One Docker network per VPC]
C --> D[Static private address]
D --> E[Container VPC attachment]
E --> F[Same-VPC container traffic]
References: src/…/VpcNetworkManager.java• L31-87 src/…/VpcNetworkManager.java• L173-260 src/…/VpcNetworkManager.java• L431-595 src/…/VpcNetworkManager.java• L906-977
Service container leases
Services that start containers outside RunInstances can still join an EC2 VPC network. VpcContainerLeases checks the subnet and VPC, leases a free private address, attaches the container, and keeps the lease as a VPC dependency. A running container keeps its address across a Floci restart when the service reclaims the address from Docker.
If Docker cannot confirm that a removed container is gone, the lease remains held. Dependency checks recheck those containers in one background pass and wait only for a short bounded period. This avoids assigning the same private address to a new container while the old network endpoint may still exist. The same lease boundary lets services such as container orchestration use EC2's subnet-deletion rules without taking ownership of the EC2 instance lifecycle.
References: src/…/VpcContainerLeases.java• L25-37 src/…/VpcContainerLeases.java• L74-197 src/…/VpcContainerLeases.java• L198-270 src/…/Ec2Service.java• L433-507
Security-group rules
Security groups preserve CIDR, IPv6, security-group, and prefix-list sources for the EC2 API. With enforcement enabled, each protected guest uses a helper-owned namespace with a default-deny policy. The policy is rebuilt when group rules, attached groups, or interface IPv6 addresses change. Group deletion checks live instances, interfaces, endpoint resources, and group references before removing the group.
The firewall matches a peer's logical ENI address to its Docker transport address. This keeps IPv4 and IPv6 rules tied to the correct address family while allowing traffic between managed resources in the same account, region, and VPC. Local DNS, DHCP, and metadata paths remain available as AWS infrastructure paths.
With enforcement disabled, selected CIDR-based TCP ingress rules can instead create host port forwards. Rules that use only a referenced security group or prefix list remain visible in the API but do not publish a host port in this mode. Enforcement requires a Linux, rootful Docker daemon.
A policy or helper failure quarantines the protected endpoint and stops its workloads. It does not allow traffic without the intended policy. Policy files are retried when Docker rejects a transient upload or command setup.
References: src/…/SecurityGroupFirewallManager.java• L40-71 src/…/SecurityGroupFirewallManager.java• L124-151 src/…/SecurityGroupFirewallManager.java• L248-379 src/…/SecurityGroupFirewallManager.java• L421-456 src/…/SecurityGroupNftCompiler.java• L24-78 src/…/SecurityGroupNftCompiler.java• L97-213
Network ACL entries
Network ACLs preserve ordered and stateless allow or deny rules for IPv4 and IPv6 traffic. The rules support protocol, direction, ICMP, and port fields for EC2 reads. The Docker VPC network does not apply them as packet filters.
References: src/…/NetworkAclEntry.java• L8-52 src/…/Ec2QueryHandler.java• L304-310
Route records
Route tables store destination-to-target relationships for IPv4, IPv6, and prefix-list destinations. IPv4 destinations use a canonical network form so create, replace, delete, and describe operations refer to the same route. Route changes do not replace the Docker network or forward Docker packets.
Peering and transit-gateway records support multi-VPC state transitions and dependency checks. They do not provide general cross-VPC packet forwarding. Deleting an egress-only gateway leaves routes that target it in blackhole state.
References: src/…/Ec2Service.java• L12693-12784 src/…/Ec2Service.java• L7761-8183 src/…/VpcRouteTableListener.java• L1-120
Addresses and reachability
Floci separates the API private address, the Docker VPC address, the Docker bridge address, and the reachable public address. This keeps EC2 responses AWS-shaped while local clients use a host route or published port that can reach the guest.
Instance addresses
The subnet MapPublicIpOnLaunch setting supplies the default public-IP choice. The launch request can override it. An Elastic IP on the primary private address takes precedence over an automatic public address. A separately supplied primary interface does not acquire an automatic public address from the launch-level choice.
Private addresses come from the subnet's effective range when Docker VPC networking is active. The allocator skips reserved positions and restores leases held by running instances after restart. If no effective range exists, the instance keeps a synthesized API address without a Docker-backed private path. A host that cannot route to Docker bridge addresses uses 127.0.0.1 with published host ports for external access. When configured to expose the Floci service network, its address can be used instead. Failed lookups retry in the background and stale results do not replace a newer container address.
References: src/…/Ec2Service.java• L4467-4475 src/…/Ec2Service.java• L5215-5256 src/…/Ec2ContainerManager.java• L1492-1609 src/…/VpcNetworkManager.java• L423-535
Instance metadata
The metadata service gives a guest its identity, placement, addresses, tags, user data, and credentials. It supports IMDSv2 token requests and IMDSv1 source-address requests. A link-local proxy inside the container forwards requests to Floci and maps the current guest address to the correct instance. The proxy supports common Linux package managers and keeps its helper process out of the guest's root control group when the guest provides an isolated writable control-group view.
The EC2 proxy uses the guest's link-local address as the stable entry point and relays to Floci's metadata service. It can use iptables or nft for the local address path and removes only the relay state that it owns. The metadata source address prefers a configured network address and falls back to the bridge address, so VPC-attached guests remain identifiable even when their reported private address differs from their default route.
The metadata path is ready only after the guest can reach the IMDS relay and read its instance identity. IMDSv2 tokens are tied to the instance and expire. An instance that requires tokens rejects tokenless reads. An IAM instance profile connects metadata credential requests to the IAM role model. Identity credentials identify the instance. Profile credentials are temporary and tied to the instance profile. Profile or role changes invalidate old sessions.
The metadata flow is:
sequenceDiagram
participant G as Guest
participant P as Link-local proxy
participant M as EC2 metadata server
participant I as Instance state and IAM
G->>P: IMDS request
P->>M: Relay with guest address
M->>I: Resolve instance and credentials
I-->>M: Metadata or temporary credentials
M-->>P: IMDS response
P-->>G: Guest response
References: src/…/Ec2MetadataServer.java• L42-49 src/…/Ec2MetadataServer.java• L175-249 src/…/Ec2MetadataProxy.java• L50-134 src/…/Ec2MetadataProxy.java• L136-321 src/…/Ec2ContainerManager.java• L2126-2156
Elastic IP associations
Elastic IPs support allocation, association, disassociation, release, and filtering. Because an invented public address cannot be routed on the caller's machine, an association reports the reachable instance address while retaining the allocation identity and pool data. Clients should refresh instance and address data after association or guest restart.
NAT gateways expose private and public address records and a stable requester-managed interface view. These records model ownership and association. They do not provide NAT packet forwarding.
References: src/…/Ec2Service.java• L5414-5465 src/…/Ec2Service.java• L8200-8379 src/…/Address.java• L11-68 src/…/NatGateway.java• L12-64
Port forwarding
Port forwarding turns selected security-group ingress into host reachability when security-group enforcement is disabled. Each selected guest port receives an allocated host port and a forwarding sidecar. The sidecar sends connections to the instance's current container address.
Forward selection
The forward set contains TCP ports from CIDR-backed IPv4 or IPv6 ingress rules. SSH is excluded because it has its own host binding. Wide ranges are limited so one rule cannot create an unbounded set of forwards.
With enforcement enabled, only ingress open to every address of a family is published. IPv4-only rules bind host IPv4 addresses, IPv6-only rules bind host IPv6 addresses, and rules open to both families accept both. Narrow CIDRs, prefix lists, and security-group sources stay on the direct container path where the firewall can see the peer identity.
References: src/…/Ec2PortForwardManager.java• L515-562 src/…/Ec2Service.java• L4667-4685 src/…/PublishedPortFamily.java• L5-16
Forward lifecycle
Forward mappings are reconciled when security-group rules or interface group assignments change. They are removed on stop or termination. Restart restores saved host-port mappings and recreates missing sidecars. The target is resolved from the guest's current Docker network address before publication. The mapping records the address family, so a change from IPv4 to IPv6 policy replaces the old sidecar rather than reusing the wrong path.
The reachability flow is:
flowchart LR
A[CIDR TCP ingress rule] --> B[Guest port]
B --> C[Allocated host port]
C --> D[Forwarding sidecar]
D --> E[Current container address]
E --> F[Guest application]
References: src/…/Ec2PortForwardManager.java• L123-223 src/…/Ec2PortForwardManager.java• L225-319 src/…/Ec2Service.java• L16630-16652 src/…/Instance.java• L281-296
Instance port bindings
Some container services run beside an EC2 instance rather than inside its guest container. Ec2InstancePorts records where such a task's host port is reachable, keyed by account, instance, and port. This lets an instance-targeted load balancer reach a task through the instance and port that the EC2 API exposes. The binding is memory-only because the task and its port do not survive a restart.
References: src/…/Ec2InstancePorts.java• L10-59
IPAM
IP Address Manager (IPAM) plans address space for clients that build networks from CIDR pools. It models administrator delegation, scopes, parent and child pools, provisioned CIDRs, and allocations.
IPAM hierarchy
An organization management account can delegate an IPAM administrator. An IPAM provides private and public scopes. Pools can form a hierarchy through a source pool. Ownership controls mutation. Shared-pool lookup supports allocation across account boundaries. BYOASN associations remain regional records.
References: src/…/Ec2IpamService.java• L137-214 src/…/Ec2IpamService.java• L246-303 src/…/IpamPool.java• L11-31
CIDR allocation
Clients provision CIDRs into pools and request a specific block or the first free block of a requested size. Allocation checks containment and overlap. Child-pool space counts as occupied in the parent. Release returns the space. Client tokens make retried create, provision, and allocate calls return the original result instead of consuming new space.
The shared IPv4 range model validates subnet and endpoint addresses. It supports containment, overlap, private-range checks, and reserved-address handling without relying on CIDR text form.
References: src/…/Ec2IpamService.java• L467-530 src/…/Ec2IpamService.java• L692-799 src/…/Ec2IpamService.java• L834-850 src/…/Cidr4.java• L41-135
Change checklist
When these files or sections are changed, remember to consider these:
- Add a new EC2 action in both Query dispatch and the owning service. Keep request fields, response XML, error codes, and account or region scope aligned.
- If shared Query parsing changes, preserve numbered-list stopping rules, filter AND/OR semantics, optional scalar handling, tag XML, and response envelopes.
- If instance-type or launch data changes, keep architecture checks, vCPU quota checks, capacity checks, CPU-credit defaults, public-IP precedence, interface groups, metadata options, and launch-template merging aligned.
- If launch-template version behavior changes, keep empty-versus-inherited source semantics, direct-field precedence, version descriptions, validation of merged data,
$Latestand$Defaultresolution, monotonic version numbers, and default or last-version deletion rules aligned. - If instance, interface, or address allocation changes, preserve canonical address checks, subnet reservations,
DescribeInstancesassociations, restart leases, metadata source registration, deterministic service-owned interface IDs, and cleanup on stop or termination. - If network-interface permission behavior changes, keep owner account scope,
INSTANCE-ATTACHstate, duplicate-grant replay, Query XML, pagination, and IAM resource ARN resolution aligned. Do not imply that a recorded grant authorizes attachment until attachment execution consumes it. - If VPC CIDRs change, keep API ranges, Docker ranges, subnet leases, fallback warnings, deployment ownership labels, stale-network cleanup, and bridge-only fallback aligned.
- If service containers use VPC leases, preserve address reclamation, bounded Docker rechecks, Docker removal checks, account and region scope, and subnet or VPC deletion dependencies.
- If security groups change, keep protocol and address-family normalization, protected namespace state, quarantine behavior, dependency checks, IPv6 updates, forward selection, policy upload retry, and restart reconciliation consistent.
- If route, gateway, endpoint, DHCP, or Client VPN behavior changes, preserve API state transitions and deletion dependencies even when Docker does not implement the packet path.
- If subnet zone handling changes, keep AvailabilityZone and AvailabilityZoneId validation, zone descriptions, endpoint placement, and available-address reporting consistent.
- If public-access controls change, preserve separate regional image and snapshot states and their valid blocking values.
- If EBS defaults or volume creation changes, keep region scope, default KMS behavior, client-token replay, request matching, and metadata-only fallback aligned with guest attachment behavior.
- If IPAM ownership or allocation changes, preserve management-account delegation, owner-only mutation, shared-pool lookup, overlap checks, and client-token replay.
- If metadata proxy or systemd guest setup changes, preserve link-local readiness, source-address registration, package-manager support, token enforcement, proxy-rule cleanup, and guest control-group isolation.
- If port publication changes, keep the persisted guest-to-host map, family-specific host binding, current container target lookup, and sidecar cleanup aligned with security-group changes.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A launch supplies security groups at both instance and primary-interface level | The request fails because the group source is ambiguous | Put groups in one location |
| An explicit interface or launch private address is already held | Creation fails with an address-in-use error | Select a free address and refresh persisted leases |
| A VPC or subnet CIDR is malformed, non-private, or conflicts with Docker space | Floci uses a warned fallback range or leaves the resource API-only | Use non-overlapping private CIDRs and inspect warnings |
| A subnet request names an invalid AvailabilityZoneId or gives a zone name that disagrees with it | Subnet creation fails before a resource is stored | Use one valid zone form or matching name and ID |
| Image and instance architectures do not match | The launch fails before a guest starts | Select compatible image and instance type |
| A Windows image is selected for a container-backed launch | The launch is rejected because the guest runtime supports Linux images only | Use a supported Linux image |
| A launch-template version combines instance requirements with an instance type | The template version is rejected before it can be used | Select one instance-shape method |
| A client tries to delete the default or last launch-template version | The version is reported as not deletable | Set another default or retain a second version |
| A retried create or allocation uses the same client token with different request data | The request fails with an idempotency mismatch | Reuse the token only for the original request |
| A network-interface permission names an invalid account or unsupported permission type | The grant is rejected before it is stored | Use a 12-digit account ID and INSTANCE-ATTACH |
| A client expects a recorded interface permission to authorize attachment | The permission is visible but attachment still follows the existing attachment rules | Treat the current permission as control-plane state only |
| A VPC or subnet is deleted while a service container lease remains | Deletion fails because a live network consumer still holds an address | Remove the container and wait for Docker removal confirmation |
| A client expects routes, ACLs, NAT, peering, or transit gateways to move Docker packets | API records change but the Docker path does not | Use same-VPC Docker reachability or explicit host forwards |
| Security-group enforcement runs without a Linux rootful Docker daemon | Protected launch fails or policy refresh quarantines workloads | Provide the required Docker runtime and helper tools |
| A CIDR-only forward is absent because ingress uses only a security-group or prefix-list source | The rule is visible in EC2 but no host port is published | Add CIDR-backed TCP ingress or enable enforcement |
| An IPv6-only forward is requested but the guest has no Docker IPv6 address | No host port is published for that application port | Provide a Docker IPv6 path or use an IPv4 rule |
| A container address changes after restart | Saved forwarding or reported reachability can target an old address | Refresh the target before restoring metadata and forwards |
| A Client VPN target remains associated during endpoint deletion | The delete request fails | Disassociate every target network first |
| A DHCP DNS list has invalid values or too many addresses | DHCP option creation or modification is rejected | Use valid values within each family limit |
| A public-access state uses an unsupported blocking value | The image or snapshot control request is rejected | Use the supported image or snapshot values |
| An IPAM retry changes or omits its client token | A second resource can be created or another CIDR can be consumed | Reuse the same token for the full retry |
| An Instance Connect endpoint or live interface still uses a security group | Group deletion fails with a dependency error | Remove the endpoint or interface group reference first |
| The metadata guest lacks a supported package manager or link-local setup fails | The instance runs without a working metadata path | Use an image with the required guest tools and refresh after restart |
| A terminated instance remains past its retention period but cleanup cannot release a dependent resource | The record stays visible and the sweep retries it later | Resolve the volume, interface, or service dependency |
Key files
| File | Why to read it |
|---|---|
| src/…/Ec2QueryHandler.java | Defines the EC2 Query action boundary, request parsing, and XML responses |
| src/…/Ec2QueryProtocol.java | Defines shared Query list, filter, scalar, tag, and XML rules |
| src/…/Ec2Service.java | Defines EC2 resource relationships, lifecycle state, addresses, persistence, interface permissions, and launch-template behavior |
| src/…/Ec2ClientTokens.java | Defines replay and mismatch behavior for idempotent create operations |
| src/…/Ec2Ids.java | Defines random and stable resource identifier forms |
| src/…/LaunchTemplate.java | Defines persisted template metadata and version history |
| src/…/Ec2LaunchTemplateSelections.java | Keeps launch-template name resolution stable during one request |
| src/…/Ec2StoredResourceArns.java | Resolves launch-template and attached interface or instance resource ARNs for authorization |
| src/…/Ec2ContainerManager.java | Connects instance records to Docker guests, metadata, protected namespaces, and lifecycle |
| src/…/Ec2TerminatedInstanceScheduler.java | Triggers delayed removal of old terminated instance records |
| src/…/Ec2MetadataProxy.java | Defines guest link-local proxy setup, relay cleanup, and source-address selection |
| src/…/Ec2MetadataServer.java | Defines guest metadata, token checks, and credential access |
| src/…/Ec2InstanceTypeCatalog.java | Defines compute, architecture, network, quota, and CPU-credit shape |
| src/…/Ec2ImageCatalog.java | Defines catalog-backed image discovery |
| src/…/AmiImageResolver.java | Maps API image identifiers to supported guest runtimes |
| src/…/Ec2VolumeBlockDeviceManager.java | Connects EBS records to persistent guest block devices |
| src/…/Ec2EbsEncryptionService.java | Defines regional EBS encryption defaults and default KMS key state |
| src/…/Ec2ClientVpnService.java | Defines Client VPN endpoint state, target networks, routes, and dependencies |
| src/…/VpcNetworkManager.java | Connects VPC and subnet CIDRs to Docker networks and private address leases |
| src/…/VpcContainerLeases.java | Connects non-EC2 service containers to VPC address leases and deletion dependencies |
| src/…/SecurityGroupFirewallManager.java | Defines protected guest namespaces, policy refresh, upload retry, and quarantine |
| src/…/SecurityGroupNftCompiler.java | Maps security-group policy to IPv4 and IPv6 endpoint traffic |
| src/…/Ec2PortForwardManager.java | Defines how security-group ingress becomes family-aware host reachability |
| src/…/Ec2InstancePorts.java | Records host ports used by service containers addressed through EC2 instances |
| src/…/Instance.java | Defines instance lifecycle, address, metadata, and persisted port state |
| src/…/InstanceNetworkInterface.java | Defines the interface view embedded in an instance |
| src/…/NetworkInterface.java | Defines standalone and requester-managed interface state and grants |
| src/…/NetworkInterfacePermission.java | Defines the cross-account interface grant record |
| src/…/PublishedPortFamily.java | Defines IPv4, IPv6, and dual-family port publication |
| src/…/Subnet.java | Defines subnet zone identity, address availability, and launch network settings |
| src/…/Ec2IpamService.java | Defines IPAM delegation, pool hierarchy, allocation, shared lookup, ownership, and replay |