Introducing a new way to review your PRs.

Read the announcement

floci-io / floci

Light, fluffy, and always free - The AWS Local Emulator alternative

View on GitHub

38 documents · Updated Nov 23, 2026

docs / svc-cloudformation

CloudFormation provisioning

CloudFormation provisioning turns a template into managed resources in Floci's AWS service emulation. It expands the template, resolves values and dependencies, calls the service that owns each resource, and records stack state for updates, deletion, recovery, and cross-service use. Account and Region define the scope for each stack and its resources.

Provisioning flow

The CloudFormation query surface routes stack, change-set, event, and StackSet actions to the provisioning system. A mutation builds a candidate resource graph, runs its lifecycle, and records stack status and resource events.

This diagram shows how a request becomes service state and stack history.

flowchart LR
    A[CloudFormation request] --> B[Stack or change-set operation]
    B --> C[Parse and transform template]
    C --> D[Resolve values and dependencies]
    D --> E[Validate resource shapes]
    E --> F[Dispatch resources]
    F --> G[Owning AWS service]
    G --> H[Physical IDs and attributes]
    B --> I[Stack status and events]
    I --> J[EventBridge status event]

Create and update requests prepare and execute a change set before normal success. A direct change-set execution accepts only an available change set. Stack mutations claim the stack before work starts, so concurrent operations do not change one stack at the same time. Status changes also produce CloudFormation-shaped status events on the account and Region's default EventBridge bus.

References: src/…/CloudFormationQueryHandler.java• L75-114 src/…/CloudFormationService.java• L562-636 src/…/CloudFormationService.java• L668-683 src/…/CloudFormationService.java• L723-807

Template parsing and transforms

CloudFormation reads template bodies as JSON or YAML. JSON is treated as a strict format when the body starts with an object or array; other valid YAML forms are also accepted. CloudFormation shorthand such as !Ref, !Sub, and !GetAtt becomes the same intrinsic form used by JSON. Parsing errors report the format and source position. src/…/CloudFormationTemplateParser.java• L12-69

The transform stage merges S3-backed AWS::Include fragments and expands AWS::Serverless-2016-10-31 resources before provisioning. AWS::Include accepts an s3://bucket/key location, including a location resolved from supported Ref or Fn::Sub expressions. The included document must be a mapping and cannot include another AWS::Include; local file paths do not reach this stage.

The transform process follows an ordered path:

  1. Parse the JSON or YAML body.
  2. Merge include fragments from S3.
  3. Expand supported SAM resources into standard CloudFormation resources.
  4. Validate the expanded values and dependency graph.
  5. Provision the active resources.

SAM expansion turns serverless functions, layers, APIs, HTTP APIs, tables, and state machines into resource graphs with their related routes, integrations, permissions, versions, aliases, authorizers, deployments, and stages. The system keeps the submitted and processed templates as separate views. A transform error stops the operation before the candidate graph is provisioned. src/…/CloudFormationService.java• L637-685

References: src/…/CloudFormationTemplateParser.java• L35-69 src/…/AwsIncludeProcessor.java• L14-25 src/…/AwsIncludeProcessor.java• L53-129 src/…/AwsIncludeProcessor.java• L143-159 src/…/CloudFormationService.java• L637-685

Template values and dependency graph

The template engine turns CloudFormation expressions into values that service APIs can use. It combines parameters, pseudo-parameters, conditions, mappings, resource IDs, resource attributes, exports, stack outputs, and dynamic references while keeping scalar, list, and JSON shapes.

Template valueResult
RefA parameter, pseudo-parameter, or resource physical ID
Fn::GetAttAn attribute published by a resource provisioner
Fn::ImportValueAn export from another stack in the same account and Region
Fn::GetStackOutputAn output read from another stack, with optional role checks
Fn::If, Fn::Split, Fn::GetAZs, or Fn::CidrA selected or generated scalar or list
Policy or definition documentJSON text with intrinsic values resolved

Conditions remove inactive resources and outputs from the active graph. References and explicit dependencies order the active resources. A changed physical ID or attribute can cause dependent resources to run again. AWS::NoValue removes a property or list member instead of sending it to the owning service.

Resource schemas form a validation boundary. They check nested property shape and convert values before a provisioner receives them. During an update, the engine also tells the provisioner whether a property was added, changed, dropped, or unchanged. This lets the resource distinguish a real change from an unchanged reference.

References: src/…/CloudFormationTemplateEngine.java• L29-32 src/…/CloudFormationTemplateEngine.java• L247-363 src/…/CloudFormationTemplateEngine.java• L365-416 src/…/CloudFormationTemplateEngine.java• L1040-1087 src/…/CfnPropertyTypes.java• L24-45 src/…/PropertyChanges.java• L12-109

Stack lifecycle

CloudFormationService owns the durable view of a stack. That view includes the submitted and processed templates, parameters, resources, events, outputs, exports, tags, change sets, policies, termination protection, and rollback state. Stack state is scoped by account and Region and survives a service restart.

Stack creation and update

Creation and update use the same broad lifecycle:

  1. Validate the operation and claim the stack for one mutation.
  2. Parse and transform the candidate template.
  3. Apply parameter defaults and resolve supported SSM parameter values.
  4. Evaluate conditions and validate resource shapes.
  5. Provision active resources in dependency order.
  6. Resolve outputs and exports.
  7. Commit the new stack view and clean displaced resources.

Change sets compare the candidate graph with the deployed graph. The comparison includes active resources, resolved parameters, conditions, imports, stack-output reads, create-only properties, and current dynamic-reference values. A create-only change uses replacement semantics. Nested AWS::CloudFormation::Stack resources deploy a child stack as part of the parent operation, and child outputs can feed the parent.

Unnamed resources keep their physical name when their identity is unchanged. A changed explicit name can require replacement or fail when the named resource cannot be replaced safely. DeletionPolicy, UpdateReplacePolicy, and retain options control whether displaced or deleted resources stay outside active stack management.

References: src/…/CloudFormationService.java• L1119-1377 src/…/CloudFormationService.java• L2743-2819 src/…/CloudFormationService.java• L2910-3009

Stack deletion and protection

Stack deletion removes resources in reverse dependency order so dependents leave before the resources they use. Termination protection blocks deletion. Retain policies and retain lists keep selected resources. A failed delete keeps the stack in DELETE_FAILED with the remaining work available for a later retry.

Replacement cleanup is separate from normal stack deletion. After a successful update, CloudFormation removes the displaced resource unless UpdateReplacePolicy: Retain applies. Cleanup records preserve ownership and retry state when removal does not finish.

References: src/…/CloudFormationService.java• L1533-1601 src/…/CloudFormationService.java• L3955-4084 src/…/CfnResourceDispatcher.java• L317-371

Resource registry and provisioners

The resource registry maps each CloudFormation resource type to a provisioner owned by the service that manages it. A provisioner reconciles the resource in that service and publishes the physical ID and attributes that later template expressions can read.

The dispatcher supplies common context such as resolved values, account, Region, stack name, prior identity, prior properties, and property changes. It also coordinates shared lifecycle work such as replacement cleanup, deletion, rollback, and stack-less Cloud Control operations.

Resource dispatch follows these rules:

  • An exact registered type takes precedence over the generic Custom::* path.
  • An unsupported type is stubbed in lenient mode or fails the stack in strict mode.
  • A disabled owning service is distinct from an unknown type. A real resource from that service is not silently replaced by a stub.
  • A create-only change creates a replacement or rejects an update when a custom name cannot be replaced safely.
  • Ownership records protect shared child resources and relationships from deletion by the wrong stack.

The provisioner boundary now includes deployment, batch and analytics, identity policy, networking, compute, data, messaging, events, operations, DNS, policy, signing, and edge services. Recent additions make CloudFormation create real CodeDeploy applications, EMR clusters and child resources, EMR on EKS virtual clusters, EMR Serverless applications, EMR Studios and session mappings, and Verified Permissions stores, templates, and policies. These resources publish service IDs and attributes, apply the service's create-only and in-place update rules, and use shared rollback and replacement handling.

Resource familyProvisioning role
CodeDeployCreates applications and reconciles stack-owned tags
EMRCreates security configurations and clusters, then manages steps, instance groups, and fleets
EMR on EKSCreates virtual clusters and updates their stack-owned tags
EMR ServerlessCreates applications and updates supported settings and tags
EMR StudioCreates Studios and session mappings with supported in-place updates
Verified PermissionsCreates policy stores, schemas, policy templates, and policies

References: src/…/CfnResourceDispatcher.java• L21-29 src/…/CfnResourceDispatcher.java• L129-193 src/…/CfnResourceDispatcher.java• L248-315 src/…/CodeDeployCfnProvisioner.java• L19-26 src/…/EmrCfnProvisioner.java• L34-61 src/…/EmrContainersCfnProvisioner.java• L20-30 src/…/EmrServerlessCfnProvisioner.java• L26-37 src/…/EmrStudioCfnProvisioner.java• L26-44 src/…/VerifiedPermissionsCfnProvisioner.java• L22-39

Dynamic references

Dynamic references defer value lookup until deployment. The resolver reads live values from SSM Parameter Store or Secrets Manager and passes the result to the provisioner. Resolution also works inside lists and text produced by intrinsic functions.

Supported values include:

  • SSM String and StringList values with optional versions.
  • Secrets Manager secret strings with an optional version stage or version ID.
  • A JSON key inside a Secrets Manager secret.
  • Secure SSM values for supported RDS password properties.

Stack state does not store secret content. It stores a digest for each resolved dynamic reference. A later change-set comparison can detect a live value change without exposing the value. An invalid lookup fails the resource operation.

References: src/…/CloudFormationTemplateEngine.java• L214-245 src/…/CloudFormationTemplateEngine.java• L434-469 src/…/ComparedTemplate.java• L44-56 src/…/CfnDynamicReferences.java• L19-242 src/…/RdsCfnProvisioner.java• L451-474

Custom resources

Custom resources extend a stack with a Lambda named by ServiceToken. CloudFormation sends the handler a lifecycle request and waits for the handler to post its result to ResponseURL. Floci uses an HTTP callback endpoint as the stand-in for the signed S3 response URL.

The lifecycle is:

  1. Resolve the service token and resource properties.
  2. Invoke the Lambda with Create, Update, or Delete.
  3. Wait for and validate the callback.
  4. Store the returned physical ID and Data values for later Ref and Fn::GetAtt use.

The supported path is a synchronous Lambda handler. The asynchronous Provider path with onEvent and isComplete polling is not emulated. An unchanged update is a no-op. A new physical ID gives the resource replacement behavior. A missing callback or inactive handler times out.

References: src/…/CustomResourceCfnProvisioner.java• L29-59 src/…/CustomResourceCfnProvisioner.java• L82-159 src/…/CfnResponseController.java• L11-47

Rollback and replacement cleanup

Rollback protects the last known-good stack view when a create or update fails. An update snapshot holds the prior template, parameters, outputs, exports, tags, and resource records. Provisioners keep the service state needed to undo an in-place change or remove a replacement.

This diagram shows the update transaction and its recovery paths.

flowchart TD
    A[Deployed stack] --> B[Save update snapshot]
    B --> C[Provision candidate graph]
    C -->|success| D[Commit stack view]
    D --> E[Clean displaced resources]
    C -->|failure| F[Restore resource records]
    F --> G[Restore service state or delete replacements]
    G --> H[UPDATE_ROLLBACK_COMPLETE or UPDATE_ROLLBACK_FAILED]

Create failure enters ROLLBACK_IN_PROGRESS and removes resources created by the operation. A clean rollback ends in ROLLBACK_COMPLETE. A cleanup failure ends in ROLLBACK_FAILED. Update failure restores the prior stack view and asks provisioners to restore service state. If restoration cannot finish, the stack ends in UPDATE_ROLLBACK_FAILED.

Shared rollback bookkeeping marks newly created entities as stack-owned during a risky operation. Provisioners also snapshot mutable state before an in-place update. Compensation failures remain visible and can create cleanup work for a later retry instead of being reported as success. ContinueUpdateRollback retries a stack in UPDATE_ROLLBACK_FAILED and can skip eligible failed resources with a warning that live state may differ from the template.

References: src/…/CloudFormationService.java• L3242-3306 src/…/CloudFormationService.java• L3501-3569 src/…/CloudFormationService.java• L3603-3767 src/…/CfnRollback.java• L30-60 src/…/CfnRollback.java• L480-560 src/…/CfnResourceDispatcher.java• L398-425

StackSet lifecycle

StackSets keep one template and apply it to account and Region targets. The administrator account stores the StackSet, instance records, and operation history. Each instance runs the ordinary stack lifecycle in its target account and Region.

Self-managed StackSets target account IDs. Service-managed StackSets target organization roots or organizational units after trusted access is enabled. Only one StackSet operation runs at a time.

The deployment flow is:

  1. Reserve the StackSet operation.
  2. Resolve direct accounts or active accounts under organization targets.
  3. Preflight and execute a change set in each target account and Region.
  4. Record each instance as successful or INOPERABLE.
  5. Aggregate instance results into the operation status.

Preflight evaluates account-sensitive conditions in the target account. Execution then uses the same account and Region, so pseudo-parameters and downstream resources match the instance. Overlapping organization targets share one instance until the last target association is removed. Instance removal can delete its backing stack or detach the instance while retaining the stack and resources.

AWS::CloudFormation::StackSet uses the same StackSet service as the API. It creates and updates the StackSet and its instance groups, removes dropped targets, and deletes instances before the StackSet. Failed updates preserve a StackSet snapshot for rollback.

References: src/…/StackSetService.java• L49-65 src/…/StackSetService.java• L131-191 src/…/StackSetService.java• L297-377 src/…/StackSetService.java• L438-505 src/…/StackSetService.java• L597-676 src/…/CloudFormationQueryHandler.java• L895-980

Cross-service orchestration

CloudFormation coordinates resources that live in different emulated services. A stack can create identity and network resources, pass their IDs and attributes through references, and connect applications to APIs, events, storage, databases, caches, delivery systems, signing profiles, policy stores, analytics clusters, and edge services.

Recent provisioners illustrate the range of contracts that CloudFormation carries across services:

Resource familyOrchestration role
CodeDeployCreates an application that other deployment resources can name
EMRBuilds a cluster with roles, configurations, steps, groups, and fleets, then exposes cluster attributes
EMR on EKSConnects a virtual cluster to a container provider and security configuration
EMR ServerlessConnects an application to runtime, capacity, network, identity, and monitoring settings
EMR StudioConnects a Studio to VPC, security, identity, storage, and session mappings
Verified PermissionsConnects policy stores with schemas, templates, policies, encryption, and deletion protection
CloudFrontConnects distributions with origins, cache and origin policies, access controls, public keys, key groups, and functions
CloudWatchCreates alarms from metric identity, dimensions, thresholds, and action targets
EKSConnects clusters and nodegroups with roles, subnets, network settings, logging, and tags
RDSConnects database instances and clusters with subnet groups, parameter groups, roles, endpoints, credentials, and protection settings
S3 VectorsConnects vector indexes to buckets while enforcing account and Region scope

The stack engine propagates physical-ID and attribute changes to dependent resources. It also records ownership for shared children such as event targets, security-group rules, DNS records, memberships, notifications, tags, and network attachments. This lets a stack remove only the relationships it owns even when an owning service stores relationships from several stacks together.

References: src/…/CloudFormationService.java• L1296-1377 src/…/CloudFormationService.java• L2910-3009 src/…/CodeDeployCfnProvisioner.java• L96-143 src/…/EmrCfnProvisioner.java• L204-278 src/…/EmrContainersCfnProvisioner.java• L105-145 src/…/EmrServerlessCfnProvisioner.java• L123-150 src/…/EmrStudioCfnProvisioner.java• L154-190 src/…/VerifiedPermissionsCfnProvisioner.java• L71-110 src/…/CloudFrontCfnProvisioner.java• L506-553 src/…/CloudWatchCfnProvisioner.java• L35-89 src/…/EksCfnProvisioner.java• L111-145 src/…/RdsCfnProvisioner.java• L389-510 src/…/S3VectorsCfnProvisioner.java• L67-120

Change checklist

When these files or sections are changed, remember to consider these:

  • When parser or transform behavior changes, keep submitted and processed templates, generated resource links, rewritten references, include locations, and dependency validation aligned.
  • When template value or schema handling changes, keep condition pruning, AWS::NoValue, list shape, resource attributes, JSON documents, and service request shape aligned.
  • When comparison or replacement rules change, check create-only values, custom names, physical IDs, dynamic-reference digests, and dependent resources together.
  • When stack state changes, keep account and Region scope aligned across persistence, outputs, exports, events, change sets, and rollback snapshots.
  • When a resource type changes, preserve one registry owner and its physical ID, attributes, ownership data, delete behavior, replacement behavior, and rollback hooks.
  • When a provisioner changes a shared child or relationship, preserve its ownership record and parent address through update, delete, and retry.
  • When a newly supported service resource is added, align its template schema, Ref and Fn::GetAtt values, service request shape, create-only properties, and disabled-service behavior.
  • When an in-place provisioner update changes tags or mutable service state, keep its snapshot, owned-key record, compensation path, and failed-rollback retry state aligned.
  • When custom-resource callbacks change, keep service-token resolution, prior properties, physical ID reuse, returned data, and synchronous callback liveness aligned.
  • When rollback changes, keep ownership markers, in-place snapshots, failed-update tracking, replacement cleanup, retry state, and status transitions distinct.
  • When StackSet targeting changes, check permission model, target resolution, target-account preflight, overlapping targets, instance status, and operation status together.
  • When a cross-service provisioner changes, check dependent IDs, published attributes, account and Region checks, service-specific update limits, and cleanup ownership together.

Important failure modes

TriggerConsequenceGuard
The template or transform is invalidThe candidate graph is not provisionedParser, include, SAM, and dependency validation
An include location is not an S3 URI or its document is not a mappingThe transform fails before resource creationInclude location and fragment-shape checks
A property has the wrong shape or an unresolved strict valueProvisioning stops before the owning service callResource schemas and strict value resolution
A stack output, export, or dependency cannot resolveA dependent resource cannot be provisionedDependency ordering and lookup checks
A create-only value changes on a custom-named resourceThe update fails instead of replacing the named resourceReplacement rules and custom-name checks
A resource type is unsupported or its service is disabledThe resource is stubbed in lenient mode or the stack fails in strict modeRegistry and dispatcher mode checks
A dynamic reference target, version, key, or type is invalidThe dependent resource fails without the intended valueLive lookup validation and digest comparison
A custom-resource handler fails or does not callbackThe resource operation fails or times outSynchronous callback status and liveness checks
An EMR cluster does not become ready or has already endedCluster creation or update fails and the stack may enter rollbackReadiness and live-resource checks
A service resource sets a read-only propertyThe provisioner rejects the resource operationRegistry shape checks and provisioner validation
A service resource changes a setting its API cannot updateThe stack reports a resource failure or leaves the setting unchanged where the service does soResource-specific update and replacement rules
A service call fails after an entity is createdRollback can leave cleanup debt or end in UPDATE_ROLLBACK_FAILEDOwnership markers, snapshots, and retry records
A deleted resource or replacement cannot be removedThe stack remains in DELETE_FAILED or retains cleanup workReverse dependency deletion and cleanup retries
A StackSet target fails in its account or RegionThe instance becomes INOPERABLE and the operation failsPer-instance status and operation aggregation

Key files

FileWhy to read it
src/…/CloudFormationQueryHandler.javaShows the public CloudFormation and StackSet request surface and its mapping to lifecycle operations
src/…/CloudFormationService.javaOwns template execution, stack state, dependency order, outputs, exports, deletion, nested stacks, change sets, and rollback
src/…/CloudFormationTemplateParser.javaDefines JSON and YAML parsing behavior and format errors
src/…/AwsIncludeProcessor.javaShows S3-backed AWS::Include expansion and transform boundaries
src/…/CloudFormationTemplateEngine.javaResolves intrinsic values, conditions, lists, JSON documents, exports, stack outputs, and dynamic references
src/…/SamTransformProcessor.javaShows the high-level SAM expansion model
src/…/CfnResourceDispatcher.javaRoutes resource types and coordinates unsupported types, deletion, replacement cleanup, and rollback
src/…/CfnRollback.javaDefines shared ownership markers, compensation, and update snapshots
src/…/CodeDeployCfnProvisioner.javaIllustrates a service application with tag-only in-place updates
src/…/EmrCfnProvisioner.javaIllustrates a parent cluster with child resources, readiness, mutable capacity, and rollback
src/…/EmrContainersCfnProvisioner.javaIllustrates a virtual cluster with create-only settings and owned tags
src/…/EmrServerlessCfnProvisioner.javaIllustrates API-shaped settings, in-place application updates, and rollback
src/…/EmrStudioCfnProvisioner.javaIllustrates a Studio and session-mapping resource pair with partial update support
src/…/VerifiedPermissionsCfnProvisioner.javaIllustrates stores, schemas, policy entities, attributes, replacement, and service rollback
src/…/StackSetService.javaApplies the stack lifecycle across account and Region instances
src/…/StackSetCfnProvisioner.javaConnects AWS::CloudFormation::StackSet resources to StackSet operations
src/…/CustomResourceCfnProvisioner.javaImplements Lambda-backed custom-resource invocation and callback handling