Skip to content
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): envFromCfnOutputs does not work when stacks have a long artifactId #17436

Closed
blimmer opened this issue Nov 9, 2021 · 5 comments · Fixed by #18039
Closed

(pipelines): envFromCfnOutputs does not work when stacks have a long artifactId #17436

blimmer opened this issue Nov 9, 2021 · 5 comments · Fixed by #18039
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. effort/small Small work item – less than a day of effort feature/pfr Product Feature Requests that originated outside of GitHub p1

Comments

@blimmer
Copy link
Contributor

blimmer commented Nov 9, 2021

What is the problem?

When using envFromCfnOutputs to pass an output to a ShellStep, the synth fails if the producing stack has a long artifactId (e.g., a long ID property):

Error: Namespace name must match regular expression: /^[A-Za-z0-9@_-]{1,100}$/, got '<long artifact id>'

Reproduction Steps

  1. Clone my sample repo:
    git clone --branch variable-namespace-bug git@github.com:blimmer/cdk-bug-reports.git
    This is a simple pipeline that uses a CfnOutput in a ShellStep. See https://github.com/blimmer/cdk-bug-reports/compare/variable-namespace-bug?expand=1 for the diff from a standard cdk init template.
  2. cd cdk-bug-reports
  3. npm ci
  4. npx cdk synth

Observe:

 npx cdk synth

/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/aws-codepipeline/lib/private/validation.ts:68
    throw new Error(`${thing} name must match regular expression: ${regex.toString()}, got '${name}'`);
          ^
Error: Namespace name must match regular expression: /^[A-Za-z0-9@_-]{1,100}$/, got 'PipelineStackProdAVeryVeryLongIdThatProbablyHasSomePurposeBeingSoLongButDoesSeemALittleBitEgregiousJustSayinDC4EA63E'
    at validateAgainstRegex (/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/aws-codepipeline/lib/private/validation.ts:68:11)
    at Object.validateNamespaceName (/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/aws-codepipeline/lib/private/validation.ts:58:3)
    at Pipeline._attachActionToPipeline (/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/aws-codepipeline/lib/pipeline.ts:369:5)
    at Stage.attachActionToPipeline (/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/aws-codepipeline/lib/private/stage.ts:155:27)
    at Stage.addAction (/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/aws-codepipeline/lib/private/stage.ts:93:29)
    at Object.produceAction (/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts:394:15)
    at CodePipeline.pipelineStagesAndActionsFromGraph (/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts:223:36)
    at CodePipeline.doBuildPipeline (/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts:177:10)
    at CodePipeline.buildPipeline (/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/pipelines/lib/main/pipeline-base.ts:70:10)
    at CodePipeline.buildJustInTime (/Users/blimmer/code/cdk-bug-reports/node_modules/@aws-cdk/pipelines/lib/main/pipeline-base.ts:82:12)

You can also see this failure in GitHub actions: https://github.com/blimmer/cdk-bug-reports/actions/runs/1441330663

What did you expect to happen?

I expected the synth to not throw an error. Even though the name is quite long, I expected CDK internals to trim the artifactId to be within the 100 character limit.

What actually happened?

A runtime error was thrown:

Error: Namespace name must match regular expression: /^[A-Za-z0-9@_-]{1,100}$/, got 'PipelineStackProdAVeryVeryLongIdThatProbablyHasSomePurposeBeingSoLongButDoesSeemALittleBitEgregiousJustSayinDC4EA63E'

CDK CLI Version

1.132.0 (build 5c75891)

Framework Version

No response

Node.js Version

14.17.6

OS

MacOS

Language

Typescript

Language Version

Version 3.9.10

Other information

Although the example attached via the repro steps seems unusual, stacks deployed with pipelines automatically get the Pipeline ID and Stage ID prepended to the Stack ID. The stack also automatically gets a 9 character ID added to the end.

So, realistically, of the maximum 100 character limit, quite a bit of it is already taken up by the pipeline / stage / suffix that's automatically added.

It would be nice if CDK automatically determined that the artifact ID was going to be too long and trimmed it for me. I see there's already a method that could potentially do this (

export function stackVariableNamespace(stack: StackDeployment) {
return stack.stackArtifactId;
}
).

Although, it doesn't look like that method is used consistently, e.g., here where artifactId is accessed directly: https://github.com/blimmer/aws-cdk/blob/e2f2a972df588ab760bcd7b6f3c9d2f49741f489/packages/@aws-cdk/pipelines/lib/blueprint/shell-step.ts#L255-L258

@blimmer blimmer added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 9, 2021
@github-actions github-actions bot added the @aws-cdk/pipelines CDK Pipelines library label Nov 9, 2021
@ryparker ryparker added effort/small Small work item – less than a day of effort p2 needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. needs-reproduction This issue needs reproduction. labels Nov 9, 2021
@rix0rrr rix0rrr added p1 and removed p2 labels Nov 22, 2021
@rix0rrr rix0rrr removed their assignment Nov 22, 2021
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 22, 2021

The solution is to limit the length of the automatically generated namespace names

@ericzbeard
Copy link
Contributor

@rix0rrr will it be possible to fix this without breaking existing stacks? Also wondering how we avoid name collisions if we truncate the id.

@ericzbeard ericzbeard added the feature/pfr Product Feature Requests that originated outside of GitHub label Dec 8, 2021
rix0rrr added a commit that referenced this issue Dec 15, 2021
The variable namespace identifier in CodePipeline allows a maximum of
100 characters. If we ever come up with an identifier that would be
too long, trim it down.

While writing tests for this, discovered that actions exhibited the same
length issues, and did the same there too.

Fixes #17436.
@ericzbeard
Copy link
Contributor

@blimmer, let us know if this resolves things for you. #18039

@mergify mergify bot closed this as completed in #18039 Dec 16, 2021
mergify bot pushed a commit that referenced this issue Dec 16, 2021
The variable namespace identifier in CodePipeline allows a maximum of
100 characters. If we ever come up with an identifier that would be
too long, trim it down.

While writing tests for this, discovered that actions exhibited the same
length issues, and did the same there too.

Fixes #17436.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@blimmer
Copy link
Contributor Author

blimmer commented Dec 18, 2021

@ericzbeard - thanks! I tested this with the sample repo from my PR description (locally linking via these steps: https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md#linking-against-this-repository) and I no longer receive the error when running synth!

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
The variable namespace identifier in CodePipeline allows a maximum of
100 characters. If we ever come up with an identifier that would be
too long, trim it down.

While writing tests for this, discovered that actions exhibited the same
length issues, and did the same there too.

Fixes aws#17436.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. effort/small Small work item – less than a day of effort feature/pfr Product Feature Requests that originated outside of GitHub p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants