SkillSprout
Chapter 3 · Lesson 2
Advanced
6 min read

StackSets and Multi-Account Infrastructure Delivery

Overview

A single stack lives in one account and one Region. CloudFormation StackSets extend a template across many accounts and Regions from a single operation. You define a stack set in an administrator account and CloudFormation creates stack instances in each target.

Think of a franchise head office issuing a standard shop layout. Instead of visiting every outlet, head office publishes one plan and each outlet builds it; when a new franchise joins, it automatically receives the same layout.

DOP-C02 scenarios use StackSets to roll out baseline controls (CloudTrail, Config, IAM roles, security groups, GuardDuty enablement) and to deploy applications to many accounts. Know the two permission models, automatic deployment, operation preferences and how StackSets fit with Control Tower.

Key Concepts

  • A stack set has a template and parameters; stack instances are the deployments in each account/Region.
  • Service-managed permissions use AWS Organizations: target OUs, enable automatic deployment for new accounts, and CloudFormation creates the needed roles.
  • Self-managed permissions require you to create AWSCloudFormationStackSetAdministrationRole and an execution role in each target account.
  • A delegated administrator member account can manage service-managed stack sets so the management account stays clean.
  • Operation preferences: maximum concurrent accounts, failure tolerance, region concurrency (sequential or parallel) and region order.
  • Retain stacks when removing instances; deleting a stack set requires deleting all instances first.
  • StackSets supports drift detection and parameter overrides per account or Region.
  • Control Tower customizations (CfCT) and Account Factory for Terraform / AFC apply templates during account provisioning.

Detailed Notes

Permission models

AspectService-managedSelf-managed
TargetsOrganizations OUs / accountsExplicit account IDs
IAM rolesCreated automaticallyYou create admin and execution roles
Auto-deploy to new accountsYesNo
Requires Organizations trusted accessYes (activate-organizations-access)No
Use caseEnterprise baselinesAccounts outside the organisation

Creating a service-managed stack set

bash
aws cloudformation activate-organizations-access
aws cloudformation create-stack-set --stack-set-name baseline-security \
  --template-body file://baseline.yaml \
  --permission-model SERVICE_MANAGED \
  --auto-deployment Enabled=true,RetainStacksOnAccountRemoval=false \
  --capabilities CAPABILITY_NAMED_IAM

aws cloudformation create-stack-instances --stack-set-name baseline-security \
  --deployment-targets OrganizationalUnitIds=ou-ab12-prod1234 \
  --regions us-east-1 eu-west-1 \
  --operation-preferences FailureTolerancePercentage=10,MaxConcurrentPercentage=25,RegionConcurrencyType=PARALLEL

Service-managed stack sets must be created in the management account or by a delegated administrator (--call-as DELEGATED_ADMIN). The management account itself is not a target of OU deployments, so deploy to it separately.

Operation preferences

SettingEffect
MaxConcurrentCount/PercentageAccounts operated on at the same time per Region
FailureToleranceCount/PercentageFailures allowed before the operation stops in that Region
RegionConcurrencyTypeSEQUENTIAL (one Region after another, ordered by RegionOrder) or PARALLEL
ConcurrencyModeSTRICT_FAILURE_TOLERANCE or SOFT_FAILURE_TOLERANCE

For production baselines, deploy to a canary OU first, with low failure tolerance, then widen.

Typical StackSets uses

  • Baseline security: IAM roles for security audit, AWS Config recorders, CloudTrail, GuardDuty detectors, EBS default encryption.
  • Cross-account roles for the pipeline to assume.
  • Networking: shared VPC modules, Route 53 resolver rules.
  • Application releases to many regional accounts (SaaS tenant per account).

Automatic deployment and its gotchas

With auto-deployment, when an account joins the OU (including via Account Factory) the template is deployed automatically; removing an account deletes or retains stacks as configured. Account joins that occur while an operation is running may be processed afterwards. Failures leave the stack instance in OUTDATED status, which you can retry via an update operation.

Parameter overrides and templates

bash
aws cloudformation update-stack-instances --stack-set-name baseline-security \
  --accounts 111111111111 --regions us-east-1 \
  --parameter-overrides ParameterKey=LogRetentionDays,ParameterValue=365

Use SSM Parameter Store dynamic references to read account-specific values, and conditions on AWS::AccountId or pseudo parameters for variations.

Drift and governance

Run stack-set drift detection for compliance reporting; AWS Config can also check stack drift in each account. Prefer StackSets over per-account pipelines for guardrails because they are centrally controlled and automatically applied to new accounts.

Control Tower, CfCT and alternatives

ToolWhen
Control Tower landing zoneEstablish multi-account foundation, guardrails (controls) and Account Factory
Customizations for Control Tower (CfCT)Pipeline that deploys StackSets/SCPs on account lifecycle events from a manifest
Account Factory for TerraformProvision accounts through Terraform
CloudFormation IaC generatorScan existing resources and produce templates to import into stacks

StackSets vs pipeline fan-out

StackSets is best for uniform baselines and automatic coverage of new accounts. A CodePipeline with parallel deploy actions gives per-account approvals and ordered promotion; combine them when needed: StackSets for guardrails, pipelines for applications.

Operating StackSets safely

  • Permission models: service-managed (Organizations integration, automatic deployment to new accounts in a target OU, no per-account roles) versus self-managed (you create AWSCloudFormationStackSetAdministrationRole and AWSCloudFormationStackSetExecutionRole).
  • Operation preferences control blast radius: MaxConcurrentPercentage or count, FailureTolerancePercentage/count, RegionConcurrencyType (SEQUENTIAL or PARALLEL) and RegionOrder. Start with a pilot OU and one Region, then widen.
  • Delegated administrator lets a security or platform account manage service-managed StackSets without using the management account.
  • Failed instances stay in the StackSet as OUTDATED or FAILED; use retry operations or override parameters per account/Region.
  • Use RetainStacksOnAccountRemoval to keep resources when an account leaves the OU, and detect drift at StackSet level.
bash
aws cloudformation create-stack-set --stack-set-name baseline-config \
  --template-body file://baseline.yml --permission-model SERVICE_MANAGED \
  --auto-deployment Enabled=true,RetainStacksOnAccountRemoval=false --capabilities CAPABILITY_NAMED_IAM
aws cloudformation create-stack-instances --stack-set-name baseline-config \
  --deployment-targets OrganizationalUnitIds=ou-ab12-prodxxxx --regions us-east-1 eu-west-1 \
  --operation-preferences FailureToleranceCount=1,MaxConcurrentCount=5,RegionConcurrencyType=SEQUENTIAL

Real World Example

Scenario: a company with 150 accounts must enable AWS Config, CloudTrail forwarding and a break-glass audit role everywhere. The security team creates a service-managed stack set in a delegated administrator account and targets the root OU with automatic deployment enabled.

They start with a Sandbox OU at 100% concurrency, then production OUs at 10% concurrency and 5% failure tolerance. New accounts created through Account Factory get the baseline within minutes, and a Config rule reports any account whose stack instance is OUTDATED.

Architecture Diagram

Service-managed StackSet rollout
Architecture
AWS Organization
Delegated admin account
Stack setbaseline-security
OU targets

Member accounts

Account Aus-east-1
Account Beu-west-1

One template deployed to every account in an OU, automatically for new accounts.

  1. 1Trusted access is enabled and a delegated administrator is registered.
  2. 2A stack set with SERVICE_MANAGED permissions is created.
  3. 3Stack instances deploy to OU accounts and Regions with concurrency limits.
  4. 4New accounts joining the OU receive the template automatically.
  5. 5Drift and OUTDATED instances are reviewed and retried.

Best Practices

  • ✓Use service-managed stack sets with a delegated administrator for organisation baselines.
  • ✓Roll out in waves with low failure tolerance and a canary OU.
  • ✓Enable automatic deployment so new accounts are compliant from day one.
  • ✓Keep templates idempotent and region-aware, using parameter overrides only when necessary.
  • ✓Combine StackSets with Config and drift detection for continuous verification.

Common Interview Questions

Exam Tips

DOP-C02 focus

  • "Automatically deploy to new accounts" = StackSets service-managed + automatic deployment.
  • "Deploy to many accounts and Regions" = StackSets, not nested stacks.
  • Self-managed model needs administration and execution roles.
  • A delegated administrator keeps StackSets work out of the management account.

Finished this lesson?

0 of 44 lessons done · 0% of the course