aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

aws_codepipeline_actions: not able to access outputs/variable of CloudFormationCreateUpdateStackAction

Open entest-hai opened this issue 2 years ago • 1 comments

Describe the bug

This is application stack

... 
 this.url = new CfnOutput(this, "Url", {
      description: "api url",
      exportName: "Url",
      value: api.url,
    });

This is a deploy action

 const deployPreProd =
      new aws_codepipeline_actions.CloudFormationCreateUpdateStackAction({
        actionName: "DeployPreProdApplication",
        templatePath: cdkBuildOutput.atPath("ApplicationStack.template.json"),
        stackName: "PreProductApplicationStack",
        adminPermissions: true,
        variablesNamespace: "PreProdVariables",
        outputFileName: "PreProdOutputs",
        output: preProdOutput,
      });

Then I want to access a output (API URL) from the deployed stack and pass to a codebuild action

 const integtestBuildAction = new aws_codepipeline_actions.CodeBuildAction({
      environmentVariables: {
        SERVICE_URL: {
          value: "HOW TO ACCESS THE API URL HERE? FROM THE DEPLOYED STACK ABOVE",
        },
      },
      actionName: "IntegTest",
      project: integtestCodeBuild,
      input: sourceOutput,
    });

The CDK document does not describe how CloudFormationCreateUpdateStackAction emit outputs/variable?

Expected Behavior

CloudFormationCreateUpdateStackAction should emit outputs/variables which are accessible to subsequent actions

Current Behavior

Not able to access outputs/variable from CloudFormationCreateUpdateStackAction. The only way to work around is to using boto3, read the deployed stack (describe) and looking for the outputs given exported names.

Reproduction Steps

Just reuse the code above

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.27.0

Framework Version

No response

Node.js Version

16.15.1

OS

Amazon Linux 2

Language

Typescript

Language Version

No response

Other information

No response

entest-hai avatar Jul 03 '22 12:07 entest-hai

if I understand your problem correctly, you are

  • Deploying an HTTP API
  • Deploying a build + test using CodePipeline

You'll need to use Parameter Store to glue the two together: When the CodePipeline resource is generated, the HTTP API has yet to be fully deployed, and it won't know it until the whole CloudFormation stack has been reified.

indrora avatar Sep 22 '22 21:09 indrora

The only way to work around is to using boto3, read the deployed stack (describe) and looking for the outputs given exported names.

When you need to make an SDK call to get some information, the best thing to do is to use a custom resource. Specifically, our helper construct AwsCustomResource makes it easy to make any arbitrary SDK call.

The suggestion above with parameter store is also a solution. But I'm also wondering why the output artifact from this action cannot be used as an input for a later step?

I think this topic will get better visibility as a discussion, converting now.

peterwoodworth avatar Nov 29 '22 23:11 peterwoodworth