Skip to content

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

@blimmer

Description

@blimmer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/pipelinesCDK Pipelines librarybugThis issue is a bug.effort/smallSmall work item – less than a day of effortfeature/pfrProduct Feature Requests that originated outside of GitHubp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions