aws-sam-cli
aws-sam-cli copied to clipboard
import existing resources into new stack
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.
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.
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 Is this feature already available or being actively worked on?
@aahung any update?
Hi, is this feature expected in any release?
@aahung any updates ?
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
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.
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/