AWS CloudFormation StackSets extends the functionality of stacks by enabling you to create, update, or delete stacks across multiple accounts and Regions with a single operation. Using an administrator account, you define and manage an AWS CloudFormation template, and use the template as the basis for provisioning stacks into selected target accounts across specified AWS Regions.
Stack sets can be created using either self-managed permissions or service-managed permissions:
- With self-managed permissions, you create the IAM roles required by StackSets to deploy across accounts and Regions. These roles are necessary to establish a trusted relationship between the account you're administering the stack set from and the account you're deploying stack instances to. More details please check self-managed permissions
-
The role in your administrator account should be named
AWSCloudFormationStackSetAdministrationRole. The role in each of your target accounts should be namedAWSCloudFormationStackSetExecutionRole.AWSCloudFormationStackSetAdministrationRole
{ "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" ], "Resource": [ "arn:aws:iam::*:role/AWSCloudFormationStackSetExecutionRole" ], "Effect": "Allow" } ] }{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ "cloudformation.amazonaws.com", "cloudformation.ap-east-1.amazonaws.com" ] }, "Action": "sts:AssumeRole" } ] }AWSCloudFormationStackSetExecutionRole
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "*", "Resource": "*" } ] }{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::admin_account_id:root" }, "Action": "sts:AssumeRole" } ] }
- With service-managed permissions, you can deploy stack instances to accounts managed by AWS Organizations. Using this permissions model, you don't have to create the necessary IAM roles; StackSets creates the IAM roles on your behalf. With this model, you can also enable automatic deployments to accounts that are added to your organization in the future. More details please check service-managed permissions
- The IAM service-linked role created in the management account has the suffix
CloudFormationStackSetsOrgAdmin. The IAM service-linked role created in each target account has the suffixCloudFormationStackSetsOrgMember - With trusted access enabled, the management account and delegated administrator accounts can create and manage service-managed stack sets for their organization. You can enable trusted access via
AWS CloudFormation consoleandAWS Organizations console - In addition to your organization's management account, member accounts with delegated administrator permissions can create and manage stack sets with service-managed permissions for the organization.
- Maximum concurrent accounts: lets you specify the maximum number or percentage of target accounts in which an operation is performed at one time.
- Failure tolerance: lets you specify the maximum number or percentage of stack operation failures that can occur, per Region, beyond which CloudFormation stops an operation automatically.
- Retain stacks: lets you keep stacks and their resources running even after they have been removed from a stack set.
- Region concurrency: lets you choose how StackSets are deployed into Regions: Sequential or Parallel
- Tags: You can add tags during stack set creation and update operations
- Set up permissions for CloudFormation StackSets
- In management account, member accounts with delegated administrator permissions, using CloudFormation AWSCloudFormationStackSetAdministrationRole
- In member accounts using CloudFormation AWSCloudFormationStackSetExecutionRole
- Check AMI public parameters existed in the Amazon Systems Manager Parameter Store
aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 --region cn-north-1 --profile china
aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 --region cn-northwest-1 --profile china- Deploy CloudFormation stacks using CloudFormation StackSets
- Go to the AWS CloudFormation StackSets console and click Create StackSet
- Using the template create VPC-EC2-S3
- Ensure that the values for the following Parameters are as follows. You can use default values for the rest.
- PublicEnabledParam - set to true
- EC2SecurityEnabledParam - set to true
- Permissions select Self-service permissions:
AWSCloudFormationStackSetAdministrationRoleandAWSCloudFormationStackSetExecutionRole - Accounts, select
Deploy stacks in accounts, and enterAccount numbers: account numbers separated by commas, likeaccount1,account2 - Specify regions, select
cn-north-1andcn-northwest-1 - Leave values for
Deployment optionsas-is:Maximum concurrent accounts: 1;Failure tolerance: 0;Region concurrency: Sequential - Click
Submit
- Check the EC2, S3, VPC already created under accounts
account1,account2and in bothcn-north-1andcn-northwest-1regions
-
Using Console
- using CloudFormation SNS_Sample
- Select
Service-managed permissions - Under
Deployment targets,- Select
Deploy to organizational units (OUs)and set theAWS OU ID Automatic deployment: EnabledAccount removal behavior: Retain stack
- Select
- Specify regions, select
cn-north-1andcn-northwest-1 - Leave values for
Deployment optionsas-is:Maximum concurrent accounts: 1;Failure tolerance: 0;Region concurrency: Sequential - Click
Submit
-
Using CLI
aws cloudformation create-stack-set \
--stack-set-name SimpleTestTopicStackSet \
--template-url file:///script/simple_stack_service_permission_sns.yaml- Check the SNS already created in all accounts under OU of
AWS OU IDand in bothcn-north-1andcn-northwest-1regions
Using the Resource: aws_cloudformation_stack_set
