# StackOutputReference

A Reference to a Stack Output.

Obtainable from: StackOutputReference.fromCfnOutput

- Source: [`pipelines/lib/blueprint/shell-step.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/pipelines/lib/blueprint/shell-step.ts#L263)

## Example

TypeScript:

```ts
class MyLambdaStep
  extends pipelines.Step
  implements pipelines.ICodePipelineActionFactory
{
  private stackOutputReference: pipelines.StackOutputReference;

  constructor(private readonly fn: lambda.Function, stackOutput: CfnOutput) {
    super('MyLambdaStep');
    this.stackOutputReference =
      pipelines.StackOutputReference.fromCfnOutput(stackOutput);
  }

  public produceAction(
    stage: codepipeline.IStage,
    options: pipelines.ProduceActionOptions
  ): pipelines.CodePipelineActionFactoryResult {
    stage.addAction(
      new cpactions.LambdaInvokeAction({
        actionName: options.actionName,
        runOrder: options.runOrder,
        // Map the reference to the variable name the CDK has generated for you.
        userParameters: {
          stackOutput: options.stackOutputsMap.toCodePipeline(
            this.stackOutputReference
          ),
        },
        lambda: this.fn,
      })
    );

    return { runOrdersConsumed: 1 };
  }

  /**
   * Expose stack output references, letting the CDK know
   * we want these variables accessible for this step.
   */
  public get consumedStackOutputs(): pipelines.StackOutputReference[] {
    return [this.stackOutputReference];
  }
}
```

Python:

```python
@jsii.implements(pipelines.ICodePipelineActionFactory)
class MyLambdaStep(pipelines.Step):

    def __init__(self, fn, stack_output):
        super().__init__("MyLambdaStep")
        self.stack_output_reference =
        pipelines.StackOutputReference.from_cfn_output(stack_output)

    def produce_action(self, stage, *, scope, actionName, runOrder, variablesNamespace=None, artifacts, fallbackArtifact=None, pipeline, codeBuildDefaults=None, beforeSelfMutation=None, stackOutputsMap):
        stage.add_action(
            cpactions.LambdaInvokeAction(
                action_name=action_name,
                run_order=run_order,
                # Map the reference to the variable name the CDK has generated for you.
                user_parameters={
                    "stack_output": stack_outputs_map.to_code_pipeline(self.stack_output_reference)
                },
                lambda_=self.fn
            ))

        return pipelines.CodePipelineActionFactoryResult(run_orders_consumed=1)public get consumedStackOutputs(): pipelines.StackOutputReference[] {
        return [this.stackOutputReference];
      }
```

Java:

```java
public class MyLambdaStep extends Step implements ICodePipelineActionFactory {
    private StackOutputReference stackOutputReference;

    public MyLambdaStep(Function fn, CfnOutput stackOutput) {
        super("MyLambdaStep");
        this.stackOutputReference = StackOutputReference.fromCfnOutput(stackOutput);
    }

    public CodePipelineActionFactoryResult produceAction(IStage stage, ProduceActionOptions options) {
        stage.addAction(
        LambdaInvokeAction.Builder.create()
                .actionName(options.getActionName())
                .runOrder(options.getRunOrder())
                // Map the reference to the variable name the CDK has generated for you.
                .userParameters(Map.of(
                        "stackOutput", options.stackOutputsMap.toCodePipeline(this.stackOutputReference)))
                .lambda(this.fn)
                .build());

        return CodePipelineActionFactoryResult.builder().runOrdersConsumed(1).build();
    }public get consumedStackOutputs(): pipelines.StackOutputReference[] {
        return [this.stackOutputReference];
      }
}
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
class MyLambdaStep : Step, ICodePipelineActionFactory
{
    private StackOutputReference stackOutputReference;

    public MyLambdaStep(Function fn, CfnOutput stackOutput) : base("MyLambdaStep")
    {
        stackOutputReference = StackOutputReference.FromCfnOutput(stackOutput);
    }

    public CodePipelineActionFactoryResult ProduceAction(IStage stage, ProduceActionOptions options)
    {
        stage.AddAction(
        new LambdaInvokeAction(new LambdaInvokeActionProps {
            ActionName = options.ActionName,
            RunOrder = options.RunOrder,
            // Map the reference to the variable name the CDK has generated for you.
            UserParameters = new Dictionary<string, object> {
                { "stackOutput", options.StackOutputsMap.ToCodePipeline(stackOutputReference) }
            },
            Lambda = Fn
        }));

        return new CodePipelineActionFactoryResult { RunOrdersConsumed = 1 };
    }public get consumedStackOutputs(): pipelines.StackOutputReference[] {
        return [this.stackOutputReference];
      }
}
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
type myLambdaStep struct {
	Step
	stackOutputReference StackOutputReference
}

func newMyLambdaStep(fn Function, stackOutput CfnOutput) *myLambdaStep {
	this := &myLambdaStep{}
	pipelines.NewStep_Override(this, jsii.String("MyLambdaStep"))
	this.stackOutputReference = pipelines.StackOutputReference_FromCfnOutput(stackOutput)
	return this
}

func (this *myLambdaStep) produceAction(stage IStage, options ProduceActionOptions) CodePipelineActionFactoryResult {
	*stage.AddAction(
	cpactions.NewLambdaInvokeAction(&LambdaInvokeActionProps{
		ActionName: options.ActionName,
		RunOrder: options.RunOrder,
		// Map the reference to the variable name the CDK has generated for you.
		UserParameters: map[string]interface{}{
			"stackOutput": options.stackOutputsMap.toCodePipeline(this.stackOutputReference),
		},
		Lambda: this.fn,
	}))

	return &CodePipelineActionFactoryResult{
		RunOrdersConsumed: jsii.Number(1),
	}
}public get consumedStackOutputs(): pipelines.StackOutputReference[] {
    return [this.stackOutputReference];
  }
```

## Properties

- `outputName`: string — Output name of the producing stack.

- `stackDescription`: string — A human-readable description of the producing stack.

## Methods

- `fromCfnOutput(output: CfnOutput): StackOutputReference // chainable` (static) — Create a StackOutputReference that references the given CfnOutput.

- `isProducedBy(stack: StackDeployment): boolean` — Whether or not this stack output is being produced by the given Stack deployment.
