AWS CloudFormation: Import Existing Resources into CloudFormation Stack

S
Sanket Jain 7th August 2022 - 4 mins read

Introduction

As you know, AWS CloudFormation service is used for automating the provisioning your infrastructure through code. But this is achieved providing a template that states all the services and resource required for the infrastructure setup. Its basically adding a list of required services with the names and specifications in a document that will setup your entire infrastructure within minutes and in one go. The advantage is if this infra document can be standardized, it can be used for multiple clients’ infra setup.

Initially what you couldn’t do was add resources that were created using AWS Console or AWS CLI to an existing stack or group these resources in a new stack to manage them is a better and more efficient way. As this was the most requested feature to AWS for CloudFormation the wait has finally ended.

What are these Features?

The Cloud Engineers or the DevOps Engineers needed to manage all the resources that were created through the Console, CLI or even CloudFormation for Dev, QA and Production environments. Now what you can do is create new stack of all these resources based on the environments to have a better administrative handle.

There may be a scenario where some resources are created for the QA environments through the console and they require to be a part of an existing QA CloudFormation stack. Because of this new feature all your QA resources can be a part of one stack by importing them into that template.

Want to know how this can be achieved?

First, we will look into creating a new stack by importing the resources. All you have to do is the following:

  • Provide a template that describes your entire stack by adding the resources you want to import. Remember while importing the resources its DeletionPolicy must be mentioned so that in case you don’t want a specific resource in you stack you can easily remove it without the worry of deleting that resource completely.


  • Next is providing the resource ids that you wish to add to your stack. In this scenario we are importing a VPC so we will be providing the VPC id.


  • Once this is done you will see that the import will be in progress and then completed. Also, the imported resources can be found in the Resources tab.

Next, we will see about importing the resources in to an existing stack:

  • Here too you have to provide a template that contains a list of resources you want to import in your existing stack.
  • Don’t forget to give your intended resource ids that will be added in your stack. Keep an eye on the Events tab to check the status and once done the Resources tab.

After your imports are completed, you are free to perform and manage your desired activities on all intended resources from a simple text file.

Points to remember

  • If you don’t mention the DeletionPolicy in your template for all the resources, your import will fail.
  • If you don’t want certain resources post import as a part of your stack without deleting them, you can simply remove its entry and configurations from the template file and your resources will remain intact.
  • While your resources are getting imported, CloudFormation will check whether your resources belong to any different stack.
  • Your desired resources should exist or else the import will fail.

Top Blog Posts

Ă—

Talk to our experts to discuss your requirements

Real boy icon sized sample pic Real girl icon sized sample pic Real boy icon sized sample pic
India Directory