Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(pipelines): unable to implement ICodePipelineActionFactory in Python #16120

Closed
amirfireeye opened this issue Aug 18, 2021 · 4 comments
Closed
Assignees
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@amirfireeye
Copy link
Contributor

I am trying to create an arbitrary CodePipeline action as part of a CDK pipeline implemented in Python. Specifically in this case it's a step function invocation, but I would like to call other types as well. No matter what I do, I keep getting the same error saying it can't find the add_action attribute on the stage object.

Reproduction Steps

Synth the following short Python code.

from aws_cdk import core, pipelines, aws_codepipeline_actions, aws_codepipeline, aws_stepfunctions
import jsii
 
 
@jsii.implements(pipelines.ICodePipelineActionFactory)
class SomeStep(pipelines.Step):
    def __init__(self, id_):
        super().__init__(id_)
 
    @jsii.member(jsii_name="produceAction")
    def produce_action(
            self, stage: aws_codepipeline.IStage,
            options: pipelines.ProduceActionOptions,
            # TODO why are these not passed?
            # *,
            # action_name, artifacts, pipeline, run_order, scope,
            # before_self_mutation=None,
            # code_build_defaults=None,
            # fallback_artifact=None
    ) -> pipelines.CodePipelineActionFactoryResult:
        stage.add_action(
            aws_codepipeline_actions.StepFunctionInvokeAction(
                state_machine=aws_stepfunctions.StateMachine.from_state_machine_arn("..."),
                action_name="foo",
                state_machine_input=aws_codepipeline_actions.StateMachineInput.literal({"foo": "bar"}),
                run_order=options["run_order"],
            )
        )
 
        return pipelines.CodePipelineActionFactoryResult(run_orders_consumed=1)
 
 
app = core.App()
 
stage = core.Stage(app, "stage")
stack = core.Stack(stage, "stack")
pipeline_stack = core.Stack(app, "pipeline-stack")
pipeline = pipelines.CodePipeline(
    pipeline_stack,
    "pipeline",
    synth=pipelines.ShellStep("synth", input=pipelines.CodePipelineSource.git_hub("foo/bar", "main"), commands=["cdk synth"])
)
 
pipeline.add_wave("wave").add_stage(stage, pre=[SomeStep("some")])
 
app.synth()

What did you expect to happen?

I expected the code to synth with no exceptions.

What actually happened?

I get the following error no matter what I try.

jsii.errors.JavaScriptError: 
  Error: '' object has no attribute 'add_action'
      at KernelHost.completeCallback (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/tmpwwmvzicu/lib/program.js:9462:35)
      at KernelHost.callbackHandler (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/tmpwwmvzicu/lib/program.js:9453:41)
      at Step.value (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/tmpwwmvzicu/lib/program.js:8323:49)
      at CodePipeline.pipelineStagesAndActionsFromGraph (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-x3iY7A/node_modules/@aws-cdk/pipelines/lib/codepipeline/codepipeline.js:154:48)
      at CodePipeline.doBuildPipeline (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-x3iY7A/node_modules/@aws-cdk/pipelines/lib/codepipeline/codepipeline.js:116:14)
      at CodePipeline.buildPipeline (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-x3iY7A/node_modules/@aws-cdk/pipelines/lib/main/pipeline-base.js:93:14)
      at CodePipeline.buildJustInTime (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-x3iY7A/node_modules/@aws-cdk/pipelines/lib/main/pipeline-base.js:101:18)
      at Object.visit (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-x3iY7A/node_modules/@aws-cdk/pipelines/lib/main/pipeline-base.js:42:57)
      at recurse (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-x3iY7A/node_modules/@aws-cdk/core/lib/private/synthesis.js:86:20)
      at recurse (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-x3iY7A/node_modules/@aws-cdk/core/lib/private/synthesis.js:98:17)
 
The above exception was the direct cause of the following exception:
 
Traceback (most recent call last):
  File "~/dev/cdk-playground/app.py", line 55, in <module>
    app.synth()
  File ".../lib/python3.9/site-packages/aws_cdk/core/__init__.py", line 16432, in synth
    return typing.cast(aws_cdk.cx_api.CloudAssembly, jsii.invoke(self, "synth", [options]))
  File ".../lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 128, in wrapped
    return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
  File ".../lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 348, in invoke
    return _callback_till_result(self, response, InvokeResponse)
  File ".../lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 216, in _callback_till_result
    response = kernel.sync_complete(
  File ".../lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 386, in sync_complete
    return self.provider.sync_complete(
  File ".../lib/python3.9/site-packages/jsii/_kernel/providers/process.py", line 382, in sync_complete
    resp = self._process.send(_CompleteRequest(complete=request), response_type)
  File ".../lib/python3.9/site-packages/jsii/_kernel/providers/process.py", line 326, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: '' object has no attribute 'add_action'
Subprocess exited with error 1

Environment

  • CDK CLI Version: 1.118.0
  • Framework Version: 1.118.0
  • Node.js Version: 16.6.2
  • OS : Mac OS X 10.15.7
  • Language (Version): Python 3.9.6

Other

I originally posted on StackOverflow but our account manager suggested it belongs here as it seems like a bug.


This is 🐛 Bug Report

@amirfireeye amirfireeye added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 18, 2021
@github-actions github-actions bot added the @aws-cdk/pipelines CDK Pipelines library label Aug 18, 2021
@rix0rrr
Copy link
Contributor

rix0rrr commented Aug 19, 2021

Reposted here aws/jsii#2963

Closing this issue as the issue will be fixed when the upstream issue is fixed.

@rix0rrr rix0rrr closed this as completed Aug 19, 2021
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@amirfireeye
Copy link
Contributor Author

@rix0rrr this issue persists even with CDK 1.120.0 and jsii 1.34.0.

(cdk-playground-5iem8SJB-py3.9) ➜  ~/Documents/dev/cdk-playground git:(master) ✗ cdk --version
1.120.0 (build 6c15150)
(cdk-playground-5iem8SJB-py3.9) ➜  ~/Documents/dev/cdk-playground git:(master) ✗ node -v      
v16.8.0
(cdk-playground-5iem8SJB-py3.9) ➜  ~/Documents/dev/cdk-playground git:(master) ✗ poetry show jsii | grep version
version      : 1.34.0
(cdk-playground-5iem8SJB-py3.9) ➜  ~/Documents/dev/cdk-playground git:(master) ✗ poetry show aws-cdk.core | grep version
version      : 1.120.0
(cdk-playground-5iem8SJB-py3.9) ➜  ~/Documents/dev/cdk-playground git:(master) ✗ cdk synth -q
hello? <jsii._reference_map.InterfaceDynamicProxy object at 0x105707370>
jsii.errors.JavaScriptError: 
  Error: '' object has no attribute 'add_action'
      at KernelHost.completeCallback (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/tmpxrnnhw1s/lib/program.js:9675:35)
      at KernelHost.callbackHandler (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/tmpxrnnhw1s/lib/program.js:9666:41)
      at Step.value (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/tmpxrnnhw1s/lib/program.js:8536:49)
      at CodePipeline.pipelineStagesAndActionsFromGraph (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-7cyzVu/node_modules/@aws-cdk/pipelines/lib/codepipeline/codepipeline.js:154:48)
      at CodePipeline.doBuildPipeline (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-7cyzVu/node_modules/@aws-cdk/pipelines/lib/codepipeline/codepipeline.js:116:14)
      at CodePipeline.buildPipeline (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-7cyzVu/node_modules/@aws-cdk/pipelines/lib/main/pipeline-base.js:93:14)
      at CodePipeline.buildJustInTime (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-7cyzVu/node_modules/@aws-cdk/pipelines/lib/main/pipeline-base.js:101:18)
      at Object.visit (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-7cyzVu/node_modules/@aws-cdk/pipelines/lib/main/pipeline-base.js:42:57)
      at recurse (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-7cyzVu/node_modules/@aws-cdk/core/lib/private/synthesis.js:86:20)
      at recurse (/private/var/folders/ln/r1dlp_xj6t57ddclvh7zgl8m0000gp/T/jsii-kernel-7cyzVu/node_modules/@aws-cdk/core/lib/private/synthesis.js:98:17)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/amir.szekely/Documents/dev/cdk-playground/app.py", line 109, in <module>
    app.synth()
  File "/Users/amir.szekely/Library/Caches/pypoetry/virtualenvs/cdk-playground-5iem8SJB-py3.9/lib/python3.9/site-packages/aws_cdk/core/__init__.py", line 16432, in synth
    return typing.cast(aws_cdk.cx_api.CloudAssembly, jsii.invoke(self, "synth", [options]))
  File "/Users/amir.szekely/Library/Caches/pypoetry/virtualenvs/cdk-playground-5iem8SJB-py3.9/lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 143, in wrapped
    return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
  File "/Users/amir.szekely/Library/Caches/pypoetry/virtualenvs/cdk-playground-5iem8SJB-py3.9/lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 363, in invoke
    return _callback_till_result(self, response, InvokeResponse)
  File "/Users/amir.szekely/Library/Caches/pypoetry/virtualenvs/cdk-playground-5iem8SJB-py3.9/lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 231, in _callback_till_result
    response = kernel.sync_complete(
  File "/Users/amir.szekely/Library/Caches/pypoetry/virtualenvs/cdk-playground-5iem8SJB-py3.9/lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 401, in sync_complete
    return self.provider.sync_complete(
  File "/Users/amir.szekely/Library/Caches/pypoetry/virtualenvs/cdk-playground-5iem8SJB-py3.9/lib/python3.9/site-packages/jsii/_kernel/providers/process.py", line 382, in sync_complete
    resp = self._process.send(_CompleteRequest(complete=request), response_type)
  File "/Users/amir.szekely/Library/Caches/pypoetry/virtualenvs/cdk-playground-5iem8SJB-py3.9/lib/python3.9/site-packages/jsii/_kernel/providers/process.py", line 326, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: '' object has no attribute 'add_action'
Subprocess exited with error 1
(cdk-playground-5iem8SJB-py3.9) ➜  ~/Documents/dev/cdk-playground git:(master) ✗ 

@amirfireeye
Copy link
Contributor Author

It works with 1.121.0. Thanks @iliapolo and @BenChaimberg for upgrading jsii!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants