skip to Main Content

I have two projects, A and B (frontend and backend). Both of these projects deploy resources to a single AWS Account using AWS CDK. Each project uses Stacks to declare AWS resources:

// Project's A stack
new PipelineStack(scope, "<LOGICAL_ID>", props)
// Project's B stack
new PipelineStack(scope, "<LOGICAL_ID>", props)

I noticed that if you name two stacks with the same <LOGICAL_ID> in different projects and deploy the code to shared AWS account, it overrides the stack of the other project (though I might be wrong).

So, are there any best practices or guidelines on how to name these stacks to prevent accidental overwrite?

2

Answers


  1. Chosen as BEST ANSWER

    My current approach involves wrapping all stack logical IDs using a custom function

    // Each project has it's own suffix function
    function suffix (name: string): string {
      return name + "suffix"
    }
    
    new PipelineStack(scope, suffix("<LOGICAL_ID>"), props)
    

  2. If you’re really set on not changing your stack ID then you can use the .stackName property to override it. However, in your case that doesn’t really buy you much so just keep with the suffix method you’ve got.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search