Lesson 5 of 5 AWS CloudFormation

Deploying Across Accounts and Regions with CloudFormation StackSets

Organisations need the same infrastructure, such as IAM roles, AWS Config rules, logging buckets and networking, in many accounts and Regions. CloudFormation StackSets deploys one template as stack instances across many targets with a single operation. This lesson explains the permission models, automatic deployment to new accounts, deployment options that control speed and risk, and the operational behaviour of StackSets.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe StackSets, stack instances and the administrator and target accounts.
  • Distinguish between self-managed and service-managed permissions and explain automatic deployment.
  • Explain how concurrency, failure tolerance and Region order control a StackSets operation.
  • Describe delegated administration, parameter overrides, drift detection and stack instance removal for StackSets.

StackSets Concepts

A stack set is a regional resource in an administrator account that contains a template, parameters and deployment settings. Each deployment target, a combination of an account and a Region, receives a stack instance, which is a reference to an ordinary CloudFormation stack in that account and Region. Creating, updating or deleting the stack set performs the same operation on the stack instances. A stack set can manage thousands of stack instances, and parameter values can be overridden for specific accounts or Regions.

The following diagram shows a stack set deployed to three accounts in three Regions.

A stack set and its stack instances. The stack set lives in an administrator account and holds a template, parameters and deployment settings. Each target, a combination of an account and a Region, gets a stack instance that refers to an ordinary stack in that account and Region. Updating the stack set updates every stack instance, and parameter values can be overridden for particular accounts or Regions.
Operations on the stack set apply to every stack instance.

Permission Models

StackSets must be able to create stacks in target accounts. There are two ways to grant this.

Self-managed permissions

The administrator account has a role, conventionally AWSCloudFormationStackSetAdministrationRole, and each target account has a role, conventionally AWSCloudFormationStackSetExecutionRole, that trusts the administration role and has permissions to create the stack's resources. The roles are created by the team, and targets are specified as account IDs. Self-managed permissions work with any accounts, including accounts outside AWS Organizations, but every new account must be given the execution role before it can be targeted.

Service-managed permissions

With AWS Organizations, trusted access for StackSets is enabled, and StackSets creates the necessary service-linked roles in member accounts automatically. Targets are specified as organisational units (OUs), and stack instances are created in every account in the OU. Automatic deployment can be enabled so that when an account joins a target OU, StackSets deploys the stack instances to it, and when an account leaves, StackSets either deletes or retains its stack instances according to a setting. Service-managed stack sets can be created from the management account or from a delegated administrator member account registered for StackSets, which avoids using the management account for daily operations. Service-managed stack sets do not deploy to the management account itself, even if it is in a targeted OU.

Self-managed
Requires AWS OrganizationsNo
Roles in target accountsCreated by you (execution role)
TargetsAccount IDs
New accountsNeed roles and an explicit deployment
Who administersAny account with the administration role
Choose when Accounts outside an organisation or custom role control.
Service-managed
Requires AWS OrganizationsYes, with trusted access
Roles in target accountsCreated automatically
TargetsOrganisational units (or accounts within OUs)
New accountsDeployed automatically with automatic deployment
Who administersManagement account or delegated administrator
Choose when Organisation-wide baselines that follow account membership.
Sort into groups

Self-managed or service-managed?

Exam skills 2.1.2 · 2.2.1

Tell apart the two StackSets permission models.

Log in to try this activity Interactive activities are free with an account.

Deployment Options

Deploying to hundreds of targets at once would turn a template error into hundreds of failures. Operation preferences control the pace and risk of each operation.

  • Maximum concurrent accounts: the number or percentage of accounts in which StackSets deploys at the same time, per Region.
  • Failure tolerance: the number or percentage of accounts per Region in which the operation can fail before StackSets stops the operation in that Region and does not continue to other Regions.
  • Region concurrency: SEQUENTIAL deploys one Region at a time in the order specified; PARALLEL deploys to all Regions at once.
  • Region order: the sequence for sequential deployments, so a low-risk Region can go first.
  • Concurrency mode: STRICT_FAILURE_TOLERANCE reduces concurrency as failures occur so that the tolerance is never exceeded; SOFT_FAILURE_TOLERANCE keeps concurrency independent of failures for faster operations.

A cautious configuration deploys sequentially by Region, with a small concurrency such as 10% and a failure tolerance of zero, so the first failure stops the rollout. This implements deployment waves across accounts. Operations on one stack set run one at a time unless managed execution is enabled, which lets StackSets run non-conflicting operations concurrently and queue the others.

Match the pairs

StackSets operation preferences

Exam skills 2.1.2

Match each operation preference with what it controls.

Log in to try this activity Interactive activities are free with an account.

Operating Stack Sets

Several behaviours matter when stack sets are used for long-term governance. The list below describes each one.

  • Updates apply to all stack instances, or to a selected subset of accounts and Regions, using the operation preferences.
  • Parameter overrides set different parameter values for particular stack instances, such as a different log retention in a regulated account.
  • Drift detection on a stack set checks every stack instance and reports drifted instances, for example where an account administrator modified a baseline role.
  • Removing stack instances can either delete the stacks and their resources or retain them, disassociating the stack from the stack set. Retaining is useful when handing resources over to an account owner.
  • Templates must be account- and Region-agnostic, using pseudo parameters and avoiding hard-coded names that would collide, such as global S3 bucket names without the account ID.
  • Dependencies between stack sets, such as a role that a Config rule stack set needs, can be expressed so that StackSets deploys them in the correct order to new accounts.

StackSets in Control Tower

AWS Control Tower uses StackSets internally to deploy its baselines, and Customizations for AWS Control Tower (CfCT) uses StackSets and SCPs defined in a repository to extend the landing zone. These are covered in the Multi-Account Governance module.

Worked example

An Organisation-Wide Security Baseline

A security team must deploy an IAM role for its incident response tooling, an Amazon EventBridge rule that forwards security findings to a central bus, and a set of AWS Config rules to every account in the Workloads OU, in four Regions. New accounts must receive the baseline without manual action, and a faulty update must not spread.

  1. Delegated administrator

    Register the security tooling account as a delegated administrator for StackSets so the management account is not used.

  2. Service-managed stack set

    Create a service-managed stack set targeting the Workloads OU in the four Regions, with automatic deployment enabled and stack instances deleted when accounts leave.

  3. Global resources

    Deploy the IAM role from a separate stack set in a single Region, because IAM is global and creating it in four Regions would conflict.

  4. Safe updates

    Use sequential Region order, 10% maximum concurrency and zero failure tolerance.

Check yourself

A stack set deploys an IAM role with a fixed name to three Regions. The first Region succeeds and the other two fail. Why?

Show answer

IAM is a global service, so a role with a fixed name can exist only once per account. Global resources should be deployed to one Region only, or given Region-specific names.

Exam Tips

Remember for the exam

  • Service-managed StackSets target OUs, create roles automatically and support automatic deployment to new accounts; self-managed StackSets need administration and execution roles in each account.
  • Use a delegated administrator for StackSets instead of the management account; service-managed stack sets do not deploy to the management account.
  • Control risk with maximum concurrent accounts, failure tolerance, sequential Region order and concurrency mode.
  • Deploy global resources such as IAM roles from one Region only; use pseudo parameters to avoid naming collisions.
  • Removing stack instances can retain the stacks' resources; drift detection works across all stack instances.