Aws-cdk: [core] Support importing existing orphaned resources to CloudFormation stacks

Created on 13 Aug 2020  路  4Comments  路  Source: aws/aws-cdk

CloudFormation has support for importing existing resources into a stack. You can use the ResourcesToImport parameter to createChangeSet to do it.

Could AWS CDK support importing existing resources? The current implementation that calls createChangeSet does not seem to pass the ResourcesToImport parameter in any situation.

I tried to search for existing issues about this. They are hard to find because many issues talk about importing exported values or importing a reference to a resource in another stack. But here I mean importing orphaned cloud resources.

Use Case

Typical use cases are:

  • Moving resources from one CloudFormation stack to another
  • Splitting CloudFormation stacks when they become too big
  • Adopting an orphaned resource because a stack was broken and had to be deleted
  • Adopting a resource that was created manually before CloudFormation supported the resource type

These use cases are important when the orphaned resource contains data, e.g. a DynamoDB table or a S3 bucket that cannot be deleted.

Proposed Solution

I am not sure about all the details that are related using to ResourcesToImport. It probably requires a lot of testing with different AWS resource types to make it work.

In a perfect world AWS CDK would automatically import named resources when it notices that the resource already exists outside the stack. It would ask the user for confirmation if there are any issues, like having to tune the resource policy/permissions/properties to make the import work.


This is a :rocket: Feature Request

@aws-cdcore feature-request needs-triage

Most helpful comment

@Jerry-AWS No. Like I said in the issue description, I'm not talking about referring to external resources. I'm talking about importing orphaned resources back into a CloudFormation stack so that CloudFormation actually takes ownership of the resource. CloudFormation supports this, so I think AWS CDK could support it too.

All 4 comments

There are ways to use existing resources in CDK apps. See the Resources topic in the Developer Guide. Does that help?

@Jerry-AWS No. Like I said in the issue description, I'm not talking about referring to external resources. I'm talking about importing orphaned resources back into a CloudFormation stack so that CloudFormation actually takes ownership of the resource. CloudFormation supports this, so I think AWS CDK could support it too.

We are tracking this in the RFC repo, see https://github.com/aws/aws-cdk-rfcs/issues/52. Closing this in favor of the RFC issues.

Is there any workaround to reattach an orphaned s3 to cdk stack ?
Because fromBucketArn doesn't allow to modify an existing s3 bucket, i am facing a deadlock ...

Was this page helpful?
0 / 5 - 0 ratings