Skip to content

codepipeline-actions: Github connection, allow Token values #27100

@Nikola-Milovic

Description

@Nikola-Milovic

Describe the bug

While setting up an AWS CDK pipeline using the pipelines.CodePipelineSource.connection method, I encountered an error indicating that the Step id cannot be unresolved. Specifically, it failed on a tokenized value ${Token[TOKEN.653]}/${Token[TOKEN.656]}, which seems to be originating from the SSM parameters githubOwner and githubRepo.

Expected Behavior

The AWS CDK pipeline should be able to resolve and handle the tokenized values from SSM parameters seamlessly, without throwing an error related to the unresolved Step id.

Current Behavior

When trying to synthesize the pipeline stack, the process fails with the error message:

You are about to destroy the CDK environment to dev, using profile project-dev.
Are you sure? (yes/no): yes
project/deployment/node_modules/aws-cdk-lib/pipelines/lib/blueprint/step.js:1
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Step=void 0;const jsiiDeprecationWarnings=require("../../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),core_1=require("../../../core"),step_output_1=
require("../helpers-internal/step-output");class Step{static sequence(steps){for(let i=1;i<steps.length;i++)steps[i].addStepDependency(steps[i-1]);return steps}constructor(id){if(this.id=id,this.dependencyFileSets=[],this.isSource=!1,this._dependencies
=new Set,core_1.Token.isUnresolved(id))throw new Error(`Step id cannot be unresolved, got '${id}'`)}get dependencies(){return Array.from(new Set([...this.dependencyFileSets.map(f=>f.producer),...this._dependencies]))}toString(){return`${this.constructo
r.name}(${this.id})`}get primaryOutput(){return this._primaryOutput}addStepDependency(step){try{jsiiDeprecationWarnings.aws_cdk_lib_pipelines_Step(step)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStac
kTrace(error,this.addStepDependency),error}this._dependencies.add(step)}addDependencyFileSet(fs){try{jsiiDeprecationWarnings.aws_cdk_lib_pipelines_FileSet(fs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captu
reStackTrace(error,this.addDependencyFileSet),error}this.dependencyFileSets.push(fs)}configurePrimaryOutput(fs){try{jsiiDeprecationWarnings.aws_cdk_lib_pipelines_FileSet(fs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationErro
r"&&Error.captureStackTrace(error,this.configurePrimaryOutput),error}this._primaryOutput=fs}discoverReferencedOutputs(structure){for(const output of step_output_1.StepOutput.findAll(structure))this._dependencies.add(output.step),step_output_1.StepOutpu
t.recordProducer(output)}get consumedStackOutputs(){return[]}}exports.Step=Step,_a=JSII_RTTI_SYMBOL_1,Step[_a]={fqn:"aws-cdk-lib.pipelines.Step",version:"2.94.0"};

                                             ^
Error: Step id cannot be unresolved, got '${Token[TOKEN.653]}/${Token[TOKEN.656]}'
    at new Step (project/deployment/node_modules/aws-cdk-lib/pipelines/lib/blueprint/step.js:1:550)
    at new CodePipelineSource (project/deployment/node_modules/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.js:1:483)
    at new CodeStarConnectionSource (project/deployment/node_modules/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.js:1:5010)
    at Function.connection (project/deployment/node_modules/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.js:1:1766)
    at new MasterPipeline (project/deployment/lib/master-pipeline.ts:29:54)
    at Object.<anonymous> (project/deployment/bin/deployment.ts:33:26)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module.m._compile (project/deployment/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions.<computed> [as .ts] (project/deployment/node_modules/ts-node/src/index.ts:1621:12)

Subprocess exited with error 1

Reproduction Steps

Set up an AWS CDK stack with parameters fetched from SSM.
Use these parameters in the pipelines.CodePipelineSource.connection method to define the source input.
Attempt to synthesize or deploy the stack.

export function getSSMParameter(scope: Construct, key: string): string {
  const value = StringParameter.valueForStringParameter(scope, key);
  if (!value) {
    throw new Error(`Parameter ${key} does not exist in SSM.`);
  }
  return value;
}

    const githubOwner = getSSMParameter(this, ParameterKeys.GithubOwner);
    const githubRepo = getSSMParameter(this, ParameterKeys.GithubRepo);
    const githubConnection = getSSMParameter(this, ParameterKeys.GithubConnectionArn);

    const artifactBucket = new s3.Bucket(this, "ArtifactBucket", {
      removalPolicy: cdk.RemovalPolicy.DESTROY,
    });

    const sourceInput = pipelines.CodePipelineSource.connection(
      `${githubOwner}/${githubRepo}`,
      getBranch(props.deployEnv),
      {
        connectionArn: githubConnection,
      },
    );

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.94.0

Framework Version

No response

Node.js Version

18.16.0

OS

Ubuntu 22.04

Language

Typescript

Language Version

Typescript ~5.0.3

Other information

Not really anything too important it was just weird that this wouldnt work.

Especially since a similar pattern can be used for source actions

		const sourceAction =
			new codepipeline_actions.CodeStarConnectionsSourceAction({
				actionName: "GitHubSource",
				output: this.sourceOutput,
				connectionArn: getSSMParameter(this, ParameterKeys.GithubConnectionArn),
				owner: getSSMParameter(this, ParameterKeys.GithubOwner),
				repo: getSSMParameter(this, ParameterKeys.GithubRepo),
				branch: getBranch(props.deployEnv),
			});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions