aws-cdk: aws codepipeline: Stage does not implement IStage in Python

Describe the bug

I’m trying to follow the documentation here: https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_codepipeline_actions/README.html#manual-approval-action. My aim is to add an action at the end of a testing stage to destroy the resources I don’t need any more.

However, when I try to call add_action on a StageDeployent object I get the error 'StageDeployment' object has no attribute 'add_action'. When I try to call it on a Stage object, I get the same error: Stage object has no attribute add_action

Expected Behavior

I expect the code to synthesize as written in the docs

Current Behavior

Error as above

Reproduction Steps

class MentorMatchPipeline(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs):
        super().__init__(scope, construct_id, **kwargs)
        pipeline = CodePipeline(self, "MentorMatchPipeline",
                                pipeline_name="Pipeline",
                                synth=ShellStep("Synth",
                                                input=CodePipelineSource.git_hub("mentor-matching-online/mentor-match", "main"),
                                                commands=["npm install -g aws-cdk",
                                                          "cd mentor-match-infra",
                                                          "python -m pip install -r requirements.txt",
                                                          "cdk synth"],
                                                primary_output_directory="mentor-match-infra/cdk.out"
                                                )
                                )
        testing_stage: Stage = MentorMatchAppStage(self, "testing")
        pipeline.add_stage(testing_stage)

        production_stage: StageDeployment = pipeline.add_stage(
            MentorMatchAppStage(self)
        )
        production_stage.add_pre(
            ManualApprovalStep('approval')
        )
        delete_action = CloudFormationDeleteStackAction(
            admin_permissions=True,
            stack_name="MentorMatchStack",
            action_name="delete test stack"
        )
        production_stage.add_action(delete_action) # this should work, but throws an AttributeError

Adding this to an existing pipeline will cause the synth to fail with the error Stage object has no attribute 'add_action'

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.79.1

Framework Version

2.79.1

Node.js Version

20.1.0

OS

Linux

Language

Python

Language Version

3.9.10

Other information

aws-cdk-lib==2.79.1 jsii==1.81.0

ETA: expanded example

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 1
  • Comments: 19 (8 by maintainers)

Most upvoted comments

I think further clarity about when one might use Pipeline over CodePipeline, or vice versa, might be helpful. I also don’t love that we have aws_cdk.aws_codepipeline.Pipeline and aws_cdk.pipelines.CodePipeline 😅

Oh, I think I see where the confusion is now.

codepipeline.Pipeline.addStage() returns a codepipeline.IStage which does have this method. pipelines.CodePipeline.addStage() returns a StageDeployment - which isn’t documented as having addAction().

Here’s our documentation on how to add an arbitrary action in our pipelines.CodePipeline. This is the same documentation snippet you just linked, but it’s our TypeScript docs which specifies that the Stage is actually a codepipeline.IStage, not a pipelines.StageDeployment

Yeah it’s not the clearest naming system. We’ll see what we can do

Thank you, was really caught there in a limbo

Seems like the way we generate the python docs makes this very easily confusing, so please let us know if you have any ideas on how to make this more clear in the docs

Thank you so much! I’m off to try to understand the difference between Pipeline and CodePipeline 😆

Hi, can I hijack this discussion. As I struggle with a more or less similar problem and tried various version and workarounds to add an action to my pipeline without success.

My code is in TypeScript but as far as I can see and also in the linked API documentation there is no method addAction or in the Python case add_action (https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_pipelines.StageDeployment.html). Or am I missing something?

The reference code I got as answer for my discussion thread is also not reproducible / working: https://github.com/aws/aws-cdk/discussions/25650

Curious if @peterwoodworth can guide us what we did wrong and how to add correctly an action to a pipeline.

Thanks already for your hard work!

Can you please provide a snippet for this?