Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use AWS CLI to import existing resources into CloudFormation

I have a collection of CloudFormation templates that I'm using to create new resources but I also have a small percentage of AWS resources that were created outside of CF that I now want to import into CF. I know how to import existing resources into CF via the AWS dashboard but I want to do it with the CLI instead.

This is the documentation I thought would help but it appears to be out of date as I don't have a "--resources-to-import" option when I run aws cloudformation create-stack help. An up-to-date example would be very helpful if this is even possible via the command-line.

like image 595
Ryan Grush Avatar asked Dec 17 '19 17:12

Ryan Grush


People also ask

How do I import an existing resource into CloudFormation?

Sign in to the AWS Management Console and open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation . On the Stacks page, choose the stack you want to import resources into. Choose Stack actions, and then choose Import resources into stack.

How do you reference existing resources in CloudFormation?

To import existing resources into a CloudFormation stack, you need to provide: A template that describes the entire stack, including both the resources to import and (for existing stacks) the resources that are already part of the stack. Each resource to import must have a DeletionPolicy attribute in the template.

Can CloudFormation update existing resource?

AWS CloudFormation updates the resource without disrupting operation of that resource and without changing the resource's physical ID. For example, if you update certain properties on an AWS::CloudTrail::Trail resource, AWS CloudFormation updates the trail without disruption.

How do I use an existing S3 bucket in CloudFormation?

Sign in to the AWS Management Console, open the AWS CloudFormation console, choose View stack, choose Create stack, and then choose With existing resources (import resources). Choose Upload a template file and then upload the template file that you created earlier.


1 Answers

In step 4 of the CLI documentation on that page, it is actually a create-change-set call instead of a create-stack call:

aws cloudformation create-change-set --change-set-type IMPORT --resources-to-import

like image 116
Pat Myron Avatar answered Nov 05 '22 08:11

Pat Myron