Home > Net >  How can I remove resources from a CfnInclude imported CloudFormation stack?
How can I remove resources from a CfnInclude imported CloudFormation stack?

Time:02-14

I'm importing an existing Cloudformation stack into CDK using the method described in the AWS documentation.

The imported stack contains resources which I want to remove from AWS, so I'm looking for some delete/remove method in the imported cfnInclude:

    const cfnInclude = new cfn_inc.CfnInclude(this, 'Template', { 
      templateFile: 'ExistingTemplate.json'
    });
    // I'm looking for a method like this:
    // cfnInclude.remove('MyResourceName');  

Is it possible to do this somehow?

CodePudding user response:

Call tryRemoveChild on the underlying Node to remove a child construct by name.

const success = cfnInclude.node.tryRemoveChild('MyFunctionToRemove');  // returns boolean

Note this is escape hatch functionality available to all Construct subclasses, not anything specific to CfnInclude.

  • Related