aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

import existing resources into new stack

Open gdw2 opened this issue 5 years ago • 11 comments

Describe your idea/feature/enhancement

I wish SAM CLI could import existing CF resources as documented here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import-new-stack.html#resource-import-new-stack-cli

Specific use case: Destroying a stack leaves some persistent resources (e.g. a database) that could be incorporated into a new stack.

Proposal

Add a --resources-to-import argument to sam deploy.

gdw2 avatar Jan 02 '20 17:01 gdw2

I'm also interested in this. My SAM app is getting large and I would like to break it into several nested apps. I think that I need this feature in order to do so.

maxmil avatar Nov 04 '20 11:11 maxmil

create-change-set (SAM CLI uses this API to create or update stacks) supports "resources-to-import" option, I think it would not be too hard to implement.

Possible UX:

sam deploy --resources-to-import resourcesToImport.txt  # AWS CLi has --resources-to-import

aahung avatar May 13 '21 19:05 aahung

@aahung Is this feature already available or being actively worked on?

icysharp avatar Jan 28 '22 08:01 icysharp

@aahung any update?

andreacfm avatar Apr 26 '22 21:04 andreacfm

Hi, is this feature expected in any release?

noisydump avatar Feb 13 '23 18:02 noisydump

@aahung any updates ?

mericozkayagan avatar Oct 03 '23 11:10 mericozkayagan

I think we can do better than asking engineers to construct this file by hand themselves. That’s one of the major dx flaws in the cf interface. I would love if sam could generate one through a guided workflow and then orchestrate the workflow to apply the changes

softprops avatar Oct 28 '23 13:10 softprops

I had an unfortunate incident where I was deleting a stack set while working on getting a resource imported, but instead deleted the entire stack in the console UI because that button is just slightly above.

I'm not blaming SAM for the incident, but it's unfortunate that the import support with SAM is harder than dealing with a normal CloudFormation import because of the transform and there's no tooling support to make it easier.

kitsunde avatar Nov 29 '23 17:11 kitsunde

There is definitely a need for this. Example resources that often have Retain for the DeletionPolicy (especially in test or prod environments) are: LogGroups, DynamoDB tables, RDS.. Without the ability to import them if they exist a sam deploy that happens after a sam delete will fail due to the resources already existing.

For LogGroups I believe CDK has baked in a Custom Resource to handle "adopting" the LogGroup if it already exists. However, there is not solution for database tables and SAM does not even handle LogGroups. I think it would be great if SAM could navigate the more complex underlying cloudformation APIs for us to do this, in the same way it simplifies serverless resource creation. TBH, it often feels like the overall developer experience is not considered when the various AWS teams create their APIs.

The following announcement is promising, but to use the "ImportExistingResources" capability you need to use the cloudformation CLI to manage changesets:

  • https://aws.amazon.com/about-aws/whats-new/2023/11/aws-cloudformation-import-parameter-changesets/

cortexcompiler avatar Mar 01 '24 15:03 cortexcompiler