-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pipelines: Runtime error when a Stage has multiple Stacks with the same stack name #30960
pipelines: Runtime error when a Stage has multiple Stacks with the same stack name #30960
Comments
Hi @Gum-Christopher-bah , thanks for reporting this. I tried to repro the issue with this code (Ref - #30449) Code - import aws_cdk as cdk
from constructs import Construct
from aws_cdk import Stack, Environment
class DeploymentStage(cdk.Stage):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
Stack(
self,
"StackEnv1",
stack_name="my-test-stack",
env=Environment(
account="111111111111",
region="us-east-1",
),
)
Stack(
self,
"StackEnv2",
stack_name="my-test-stack",
env=Environment(
account="333333333333",
region="us-east-2",
),
) Pipeline stack from aws_cdk import (
# Duration,
Environment,
Stack,
pipelines
)
from constructs import Construct
from pipeline_issue.deployment_stage import DeploymentStage
class PipelineIssueStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
pipeline = pipelines.CodePipeline(
self,
"Pipeline",
cross_account_keys=True,
synth=pipelines.ShellStep("Synth",
input=pipelines.CodePipelineSource.git_hub("khushai/test01", "main"),
commands=["npm ci", "npm run build", "npx cdk synth"],
),
)
pipeline.add_stage(DeploymentStage(self, "Production")) app.py #!/usr/bin/env python3
import os
import aws_cdk as cdk
from pipeline_issue.pipeline_issue_stack import PipelineIssueStack
app = cdk.App()
PipelineIssueStack(app, "PipelineIssueStack",
env=cdk.Environment(account='333333333333', region='us-east-1'),
)
app.synth() Error
AFAIK, the resource Physical names have some constraints when being used across regions or cross-envoironment references, and should not produce any issue here since we are using the same stack in different regions. |
Thanks @khushail for taking another look at this. |
As @khushail is on leave I am taking over this issue. Looks like you are deploying two stacks with exactly the same stack name but in different regions. Is it correct? |
I can reproduce this using TypeScript as well. The workaround is to leave export class DeploymentStage extends Stage {
constructor(scope: Construct, id: string) {
super(scope, id);
new Stack(this, 'StackEnv1', {
// stackName: 'my-test-stack',
env: {
account: DEFAULT_ACCOUNT_ENV,
region: 'us-east-1'
}
});
new Stack(this, 'StackEnv2', {
// stackName: 'my-test-stack',
env: {
account: DEFAULT_ACCOUNT_ENV,
region: 'us-west-2'
}
});
}
} I am making it a p1 as this does not have any workaround. |
Hello @pahud, appreciate the second set of eyes here.
Yes, this is correct. I'm actually unable to omit the stack name from my stacks, because the stacks are already deployed unfortunately. Passing the stackname explicitly was the method I found best to deal with pipelines stack adoptions, because changing the scope from the app to a stage in the pipeline would always generate new stack names and thus new resources which was not desirable. My flow has been: Create stacks in app, deploy, validate, add stacks as is to pipeline. Which has worked well in the past when I named the stacks like |
Comments on closed issues and PRs are hard for our team to see. |
1 similar comment
Comments on closed issues and PRs are hard for our team to see. |
Describe the bug
This is a duplicate of issue #30449 which should not have been closed.
To provide additional context, if you have an app that you are deploying without pipelines, this behavior works, because the logical ids are different. Using waves only solves the case where you have two stacks with no other dependencies, or dependencies that are in the same region. If you have stacks which consume variables or exports from other stacks cross region by passing
crossRegionReferences: true
it is not possible to split these stacks into separate stages, because it is not possible to consume variables from stage to stage. This causes working cdk apps to be unable to be adopted by cdk pipelines.Expected Behavior
App is able to synth and deploy
Current Behavior
Stacks with the same name but different IDs in the same stage cause a runtime error:
Reproduction Steps
See duplicate issue
Possible Solution
Add an explicit override parameter that can be used to bypass this check (which I'm sure does save a lot of headaches if code gets mistakenly copy pasted)
Additional Information/Context
No response
CDK CLI Version
2.150.0 (build 3f93027)
Framework Version
No response
Node.js Version
v18.20.4
OS
Mac
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: