Self-managed stack import for AWS CloudFormation StackSets - AWS CloudFormation

Self-managed stack import for AWS CloudFormation StackSets

The AWS CloudFormation stack import operation can import existing stacks into new or existing stack sets, so that you can migrate existing stacks to a stack set in one operation. StackSets extends the functionality of stacks, so you can create, update, or delete stacks across multiple accounts and Regions with a single operation.

For example, if you have a stack that specifies an administrator AWS Identity and Access Management (IAM) role across multiple accounts, you can import that stack into a stack set. By using stack import, you avoid downtime and outages without deleting and recreating those resources. Once the stack is imported into a stack set, the original stack will become a stack instance of the newly generated stack set.

Self-managed requirements for stack import

In addition to the Requirements for stack import section, self-managed stack imports requires the following.

  • The stack import operation supports creating a stack set with self-managed permissions.

  • The stack import operation requires an administrator account in which you create a stack set and a target account that contains a stack.

  • The target account must have permission to use the GetTemplate operation with the input of stack ID or ARN. Because of that, your administrator account must be granted AWSCloudFormationStackSetsAdminstration or AWSCloudFormationStackSetsExectionRole permissions.

Import a stack into a new stack set

Import a stack into a new stack set using the AWS Management Console

To import a stack into a stack set, identify a stack that contains the resource you want to import.

  1. Sign in to the AWS Management Console and open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation.

  2. From the navigation pane, choose StackSets.

  3. At the top of the StackSets page, choose Create StackSet.

  4. On the Choose a template page, specify a template by one of the following options and select Next.

    • Choose Amazon S3 URL and specify the URL for your template in the text box.

    • Choose Upload a template file and browse for your template.

    • Choose From stack ID and enter your stack ID.

  5. On the Specify StackSet details page, enter the name of a stack set you want to create and select Next.

    (Optional) Enter a description of the stack set.

  6. On the Configure StackSet options page, review your choices and select Next.

  7. On the Set deployment options page, select Import stacks to stack set.

  8. Enter the stack ID of the stack you want to import in the Stacks to import field. For example, arn:123456789101:us-east-1:StackToImport.

    (Optional) Select Add another stack ID and enter the stack ID of another stack you want to import. You may add up to 10 stacks per stack import operation.

  9. Review your deployment options and select Next.

  10. On the Review page, review your choices and your stack set's properties. When you are ready to import your stack into your stack set, select Submit.

Results: The imported stack is now a stack instance of the specified stack set. To learn more about the stack import status, see Stack set and stack instance status codes.

Import a self-managed stack into an existing stack set

Import a stack into an existing stack set using the AWS Management Console

To import an existing stack into a stack set, identify a stack that contains the resource you want to import.

  1. Sign in to the AWS Management Console and open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation.

  2. From the navigation pane, choose StackSets.

  3. On the StackSets page, select the stack set that you want to import a stack into.

  4. With the stack set selected, choose Add stacks to StackSet from the Actions menu.

  5. On the Set deployment options page, select Import stacks to stack set and enter the stack ID of the stack you want to import in the Stacks to import field. For example, arn:123456789101:us-east-1:StackToImport.

    (Optional) Select Add another stack ID and enter the stack ID of another stack you want to import. You may add up to 10 stacks per stack import operation.

  6. Choose Next.

  7. On the Specify overrides page, review your choices and select Next.

  8. On the Review page, review your choices and your stack set's properties. When you are ready to create your stack set, choose Submit.

Results: The imported stack is now a stack instance of the specified stack set. To learn more about the stack import status, see Stack set and stack instance status codes.

Importing a stack into a stack set (AWS CLI)

Import a stack into a stack set

To import an existing stack into a stack set, identify a stack that contains the resources you want to import. In this example, the stack to import is arn:123456789101:us-east-1:StackToImport.

  1. Create a stack set from a stack ID by specifying the full ARN of the CloudFormation stack to be imported..

    aws cloudformation create-stack-set \ --stack-id "arn:aws:cloudformation:us-east-1:123456789012:stack/StackToImport/f449b250-b969-11e0-a185-5081d0136786" \ --stack-set-name "SingleStackSetName" \ --permission-model "SELF_MANAGED" \ --administration-role-arn "arn:aws:iam::123456789012:role/AWSCloudFormationStackSetAdministrationRole" \ --execution-role-name "AWSCloudFormationStackSetExecutionRole"
  2. Import a specified stack to your stack set.

    aws cloudformation import-stacks-to-stack-set \ --stack-ids "arn:aws:cloudformation:us-east-1:123456789012:stack/StackToImport/f449b250-b969-11e0-a185-5081d0136786" \ --stack-set "SingleStackSetName" \ --permission-model SELF_MANAGED \ --administration-role-arn "arn:aws:iam::123456789012:role/AWSCloudFormationStackSetAdministrationRole" \ --execution-role-name "AWSCloudFormationStackSetExecutionRole"
  3. Clone the imported stack into other Regions and accounts.

    aws cloudformation create-stack-instances \ --stack-set-name "StackSetToWhichStackimported" \ --accounts "123556789101" \ --regions "us-east-1"

Import stacks into a stack set

To import existing stacks into a stack set, identify the stacks that contains the resources you want to import. In this example, the stack to import is arn:aws:cloudformation:123456789101:us-east-1:stack/StackToImport1/f449b250-b969-11e0-a185-5081d0136786 and arn:aws:cloudformation:123456789101:us-east-1:stack/StackToImport2/f449b250-b969-11e0-a185-5081d0136786.

  1. Create a stack set from a stack ID.

    aws cloudformation create-stack-set \ --stack-id "arn:123456789101:us-east-1:StackToImport" \ --stack-set-name "StackSetName" \ --permission-model "SELF_MANAGED" \ --administration-role-arn "arn:aws:iam::123456789012:role/AWSCloudFormationStackSetAdministrationRole" \ --execution-role-name "AWSCloudFormationStackSetExecutionRole"
  2. Import specified stacks to your stack set.

    aws cloudformation import-stacks-to-stackset --stack-ids "arn:aws:cloudformation:123456789101:us-east-1:stack/StackToImport1/f449b250-b969-11e0-a185-5081d0136786, arn:aws:cloudformation:123456789101:us-east-1:stack/StackToImport2/f449b250-b969-11e0-a185-5081d0136786" \ --stack-set "StackSetName" --permission-model SELF_MANAGED \ --administration-role-arn "arn:aws:iam::123456789012:role/AWSCloudFormationStackSetAdministrationRole" \ --execution-role-name "AWSCloudFormationStackSetExecutionRole"
  3. Clone the imported stack into other Regions and accounts.

    aws cloudformation create-stack-instances \ --stack-set-name "StackSetName" \ --accounts "123456789012" \ --regions "us-east-1"