aws cdk python: error when adding codedeploy action as stage to codepipeline (jsii.errors.JSIIError: Cannot read property 'region' of undefined)

Viewed 711

If I remove the codedeploy stage the codepipeline creates and executes the Source (GitHub) and Build (docker image to ECR) stages. In this case, I also create a new ECS cluster, which gets created as well as the expected service.

This is the portion of the code:

fargate_service = ecs_patterns.ApplicationLoadBalancedFargateService(self, parms["ecs_fargate_service"],
            cluster = ecs_cluster,
            task_definition = task_definition,
            public_load_balancer = True,
            desired_count = 2,
            listener_port = 80,
            min_healthy_percent = 100,
            max_healthy_percent = 200,
            assign_public_ip = False,                
        )

deploy_action = codepipeline_actions.EcsDeployAction(
            action_name = 'DeployAction',
            service = fargate_service,
            image_file = codepipeline.ArtifactPath(build_output, 'imagedefinitions.json')
        )

pipeline = codepipeline.Pipeline(self, "CodePipeline",
            pipeline_name=parms["pipeline_name"]+"test",
            cross_account_keys = False,
            stages=[
                codepipeline.StageProps(stage_name="Source", actions=[source_action]),
                codepipeline.StageProps(stage_name="Build", actions=[build_action]),
                codepipeline.StageProps(stage_name="Deploy-to-ECS", actions=[deploy_action])
            ]
        )

If a remove this line codepipeline.StageProps(stage_name="Deploy-to-ECS", actions=[deploy_action]) there's no errors and the stack works.

I already tried the following tests:

  • Creation of the Codepipeline referencing an existing ECS cluster and in this case, there are no errors and the deploy stage works as expected.
  • Checked the documentation and there is no way to specify the region to the Codepipeline project.

This is the error

jsii.errors.JavaScriptError: 
  TypeError: Cannot read property 'region' of undefined
      at RichAction.get effectiveRegion [as effectiveRegion] (/tmp/jsii-kernel-wOdXOf/node_modules/@aws-cdk/aws-codepipeline/lib/private/rich-action.js:61:111)
      at RichAction.get isCrossRegion [as isCrossRegion] (/tmp/jsii-kernel-wOdXOf/node_modules/@aws-cdk/aws-codepipeline/lib/private/rich-action.js:31:61)
      at Pipeline.ensureReplicationResourcesExistFor (/tmp/jsii-kernel-wOdXOf/node_modules/@aws-cdk/aws-codepipeline/lib/pipeline.js:377:21)
      at Pipeline._attachActionToPipeline (/tmp/jsii-kernel-wOdXOf/node_modules/@aws-cdk/aws-codepipeline/lib/pipeline.js:337:38)
      at Stage.attachActionToPipeline (/tmp/jsii-kernel-wOdXOf/node_modules/@aws-cdk/aws-codepipeline/lib/private/stage.js:124:31)
      at Stage.addAction (/tmp/jsii-kernel-wOdXOf/node_modules/@aws-cdk/aws-codepipeline/lib/private/stage.js:71:33)
      at new Stage (/tmp/jsii-kernel-wOdXOf/node_modules/@aws-cdk/aws-codepipeline/lib/private/stage.js:28:18)
      at Pipeline.addStage (/tmp/jsii-kernel-wOdXOf/node_modules/@aws-cdk/aws-codepipeline/lib/pipeline.js:272:23)
      at new Pipeline (/tmp/jsii-kernel-wOdXOf/node_modules/@aws-cdk/aws-codepipeline/lib/pipeline.js:239:18)
      at /tmp/tmpg46d0z4s/lib/program.js:8367:58

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

Traceback (most recent call last):
  File "app.py", line 40, in <module>
    pipeline = EcsCicdStack(main_stack, "Pipeline-"+parms["stage"], vpc=vpc_stack.vpc, parms=parms)
  File "/mnt/e/Proyectos/ecs-cicd/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 86, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/mnt/e/Proyectos/ecs-cicd/ecs_cicd/ecs_cicd_stack.py", line 190, in __init__
    pipeline = codepipeline.Pipeline(self, "CodePipeline",
  File "/mnt/e/Proyectos/ecs-cicd/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 86, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/mnt/e/Proyectos/ecs-cicd/.venv/lib/python3.8/site-packages/aws_cdk/aws_codepipeline/__init__.py", line 4030, in __init__
    jsii.create(Pipeline, self, [scope, id, props])
  File "/mnt/e/Proyectos/ecs-cicd/.venv/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 290, in create
    response = self.provider.create(
  File "/mnt/e/Proyectos/ecs-cicd/.venv/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 344, in create
    return self._process.send(request, CreateResponse)
  File "/mnt/e/Proyectos/ecs-cicd/.venv/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 326, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Cannot read property 'region' of undefined

This is the configuration of my environment:

CDK CLI Version : 1.120.0 (build 6c15150)
Framework Version: 1.120.0 (build 6c15150)
Node.js Version: v16.8.0
OS : Ubuntu 20.04 LTS
Language (Version): Python 3.8.2

I would really appreciate it if you could give me an idea as to where to look at.

Thanks in advance!

Regards.

1 Answers
Related