Self-managed stack import using the AWS Management Console or AWS CLI - AWS CloudFormation

Self-managed stack import using the AWS Management Console or AWS CLI

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 administration 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 an existing stack into a new stack set (console)

Before you begin, identify the stack that 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:aws:cloudformation:us-east-1:123456789012:stack/StackToImport/f449b250-b969-11e0-a185-5081d0136786.

    (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 StackSets status codes.

Import an existing stack into an existing stack set (console)

Before you begin, identify the stack that 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:aws:cloudformation:us-east-1:123456789012:stack/StackToImport/f449b250-b969-11e0-a185-5081d0136786.

    (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 StackSets status codes.

Import a stack into a stack set (AWS CLI)

To import an existing stack into a new stack set

The following create-stack-set command creates a stack set and imports the specified stack. The stack to import is identified by its ARN. Replace the placeholder text with your own information.

aws cloudformation create-stack-set \ --stack-set-name MyStackSet \ --stack-id arn:aws:cloudformation:us-east-1:123456789012:stack/StackToImport/466df9e0-0dff-08e3-8e2f-5088487c4896 \ --administration-role-arn arn:aws:iam::123456789012:role/AWSCloudFormationStackSetAdministrationRole \ --execution-role-name AWSCloudFormationStackSetExecutionRole
To import an existing stack into an existing stack set

The following import-stacks-to-stack-sets command imports the specified stack into the MyStackSet stack set. The stack to import is identified by its ARN. Replace the placeholder text with your own information.

aws cloudformation import-stacks-to-stack-set \ --stack-set MyStackSet \ --stack-ids arn:aws:cloudformation:us-east-1:123456789012:stack/StackToImport/f449b250-b969-11e0-a185-5081d0136786

To specify more than one stack, use the following format for the value of the --stack-ids option.

--stack-ids "arn_1" "arn_2"
To clone the imported stack into other Regions and accounts

The following create-stack-instances command adds stack instances to your stack set. Replace the placeholder text with your own information.

aws cloudformation create-stack-instances \ --stack-set-name MyStackSet \ --accounts '["account_ID_1","account_ID_2"]' \ --regions '["region_1","region_2"]'

Reverting a stack instance import operation

To revert a stack import operation, complete the following tasks:

  1. Specify a DeletionPolicy attribute of Retain for each resource that you want to keep after the stack instance is deleted. For more information, see Reverting an import operation.

  2. Delete stack instances from your stack set. For more information, see Delete stack instances using the CloudFormation console or AWS CLI.

  3. Delete your stack set. For more information, see Delete a stack set using the CloudFormation console or AWS CLI.

Results: The revert operation has deleted the stack instance and retained the stack's resources.