aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.55k stars 3.87k forks source link

(codepipeline): CrossRegionSupportStack Stack name must match the regular expression #31436

Open jsunico opened 2 weeks ago

jsunico commented 2 weeks ago

Describe the Bug

I have a State Machine from another region that is being imported to CDK via StateMachine.fromStateMachineArn. When this state machine is added as cross-region StepFunctionInvokeAction to the pipeline an error is thrown.

Regression Issue

Last Known Working CDK Version

No response

Expected Behavior

Cross-region action can be added to the pipeline.

Current Behavior

Error: Stack name must match the regular expression: /^[A-Za-z][A-Za-z0-9-]*$/, got '${Token[TOKEN.840]}-support-eu-west-1'
    at new Stack (node_modules/aws-cdk-lib/core/lib/stack.js:1:2505)
    at new CrossRegionSupportStack (node_modules/aws-cdk-lib/aws-codepipeline/lib/private/cross-region-support-stack.js:1:1798)
    at Pipeline.createSupportResourcesForRegion (node_modules/aws-cdk-lib/aws-codepipeline/lib/pipeline.js:1:10279)
    at Pipeline.obtainCrossRegionSupportFor (node_modules/aws-cdk-lib/aws-codepipeline/lib/pipeline.js:1:9122)
    at Pipeline.ensureReplicationResourcesExistFor (node_modules/aws-cdk-lib/aws-codepipeline/lib/pipeline.js:1:8644)
    at Pipeline._attachActionToPipeline (node_modules/aws-cdk-lib/aws-codepipeline/lib/pipeline.js:1:7708)
    at Stage.attachActionToPipeline (node_modules/aws-cdk-lib/aws-codepipeline/lib/private/stage.js:1:3087)
    at Stage.addAction (node_modules/aws-cdk-lib/aws-codepipeline/lib/private/stage.js:1:1716)
    at new Stage (node_modules/aws-cdk-lib/aws-codepipeline/lib/private/stage.js:1:678)
    at Pipeline.addStage (node_modules/aws-cdk-lib/aws-codepipeline/lib/pipeline.js:1:6662)

Reproduction Steps

Possible Solution

NA

Additional Information/Context

No response

CDK CLI Version

2.158.0

Framework Version

No response

Node.js Version

18.20.4

OS

WSL Ubuntu 20

Language

TypeScript

Language Version

~4.6.4

Other information

No response

khushail commented 2 weeks ago

Hey @jsunico , thanks for reaching out. From the initial error check, it looks like the stack name given by you, is the issue, not the code. https://github.com/aws/aws-cdk/blob/bf3764fe6046799a2a6e074b39b9a5f4474c603c/packages/aws-cdk-lib/core/lib/stack.ts#L455

Found somewhat similar issue in the past - https://github.com/aws/aws-cdk/issues/23098 It would be more helpful if you could share the minimal repro code with the stack name you are using.

github-actions[bot] commented 1 week ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

jsunico commented 1 week ago

Hi @khushail, so I tried to reproduce it in a new project here: https://github.com/jsunico/aws-cdk-repro-cross-region-action-in-pipeline

I started off with just a single stack which is generated by cdk init. I didn't experience the issue. I then switch to nested stack to align it with our project setup and was able to reproduce the issue.

This is the error you'll get when running npx cdk synth

Error: Stack name must match the regular expression: /^[A-Za-z][A-Za-z0-9-]*$/, got '${Token[TOKEN.21]}-support-service'
    at new Stack (github-issues/pipeline-cross-region/node_modules/aws-cdk-lib/core/lib/stack.js:1:4798)
    at new CrossRegionSupportStack (github-issues/pipeline-cross-region/node_modules/aws-cdk-lib/aws-codepipeline/lib/private/cross-region-support-stack.js:1:1984)
    at Pipeline.createSupportResourcesForRegion (github-issues/pipeline-cross-region/node_modules/aws-cdk-lib/aws-codepipeline/lib/pipeline.js:1:14004)
    at Pipeline.obtainCrossRegionSupportFor (github-issues/pipeline-cross-region/node_modules/aws-cdk-lib/aws-codepipeline/lib/pipeline.js:1:12840)
    at Pipeline.ensureReplicationResourcesExistFor (github-issues/pipeline-cross-region/node_modules/aws-cdk-lib/aws-codepipeline/lib/pipeline.js:1:12360)
    at Pipeline._attachActionToPipeline (github-issues/pipeline-cross-region/node_modules/aws-cdk-lib/aws-codepipeline/lib/pipeline.js:1:11358)
    at Stage.attachActionToPipeline (github-issues/pipeline-cross-region/node_modules/aws-cdk-lib/aws-codepipeline/lib/private/stage.js:1:3313)
    at Stage.addAction (github-issues/pipeline-cross-region/node_modules/aws-cdk-lib/aws-codepipeline/lib/private/stage.js:1:1928)
    at new Stage (github-issues/pipeline-cross-region/node_modules/aws-cdk-lib/aws-codepipeline/lib/private/stage.js:1:888)
    at Pipeline.addStage (github-issues/pipeline-cross-region/node_modules/aws-cdk-lib/aws-codepipeline/lib/pipeline.js:1:9264)

From the error above, it seems that the method below is not getting the correct pipelineStackName. In a single stack setup, it can successfully get the stack name but in a nested stack setup it is returning ${Token[TOKEN.21]}.

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-codepipeline/lib/private/cross-region-support-stack.ts#L153-L155

khushail commented 1 week ago

Hi @jsunico , thanks for sharing the repro code and your investigation.

I found various related issues around this one ,sharing few of those - https://github.com/aws/aws-cdk/issues/6190 https://github.com/aws/aws-cdk/issues/27746 https://github.com/aws/aws-cdk/issues/5029 https://github.com/aws/aws-cdk/pull/22223 PR - https://github.com/aws/aws-cdk/pull/4745 , https://github.com/aws/aws-cdk/pull/6419

Although relative PRs have been merged but this CrossAccountRegion deployment is causing the issue. I faced the sImilar issue when tried to deploy the code shared by you. I checked all the Pipeline related guidelines, still getting this issue -

Screenshot 2024-09-18 at 12 13 59 PM

This surely seems a bug.

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-codepipeline/lib/private/cross-region-support-stack.ts#L153-L155

I am marking it as P1, requesting further action/inputs from the core team.