skip to Main Content
 @jsii/kernel.SerializationError: Passed to parameter props of new aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationTargetGroup: Unable to deserialize value as aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationTargetGroupProps | undefined
  ├── 🛑 Failing value is an object
  │      { '$jsii.struct': [Object] }
  ╰── 🔍 Failure reason(s):
      ╰─ Key 'targets': Unable to deserialize value as array<aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationLoadBalancerTarget> | undefined
          ├── 🛑 Failing value is an array
          │      [ '${Token[TOKEN.111]}', '${Token[TOKEN.137]}' ]
          ╰── 🔍 Failure reason(s):
              ╰─ Index 0: Unable to deserialize value as aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationLoadBalancerTarget
                  ├── 🛑 Failing value is a string
                  │      '${Token[TOKEN.111]}'
                  ╰── 🔍 Failure reason(s):
                      ╰─ Value does not have the "$jsii.byref" key
      at Object.process (C:UsersAcerAppDataLocalTemptmptnruo9odlibprogram.js:11477:19)
      at Kernel._Kernel_toSandbox (C:UsersAcerAppDataLocalTemptmptnruo9odlibprogram.js:10455:25)
      at C:UsersAcerAppDataLocalTemptmptnruo9odlibprogram.js:10471:38
      at Array.map (<anonymous>)
      at Kernel._Kernel_boxUnboxParameters (C:UsersAcerAppDataLocalTemptmptnruo9odlibprogram.js:10471:23)
      at Kernel._Kernel_toSandboxValues (C:UsersAcerAppDataLocalTemptmptnruo9odlibprogram.js:10459:101)
      at Kernel._Kernel_create (C:UsersAcerAppDataLocalTemptmptnruo9odlibprogram.js:10119:115)
      at Kernel.create (C:UsersAcerAppDataLocalTemptmptnruo9odlibprogram.js:9790:93)
      at KernelHost.processRequest (C:UsersAcerAppDataLocalTemptmptnruo9odlibprogram.js:11707:36)
      at KernelHost.run (C:UsersAcerAppDataLocalTemptmptnruo9odlibprogram.js:11667:22)

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

Traceback (most recent call last):
  File "C:UsersAcerDesktopAWS DevopsCDKapp.py", line 10, in <module>
    CdkEc2Stack(app, "CdkEc2Stack")
  File "C:Program FilesPython312Libsite-packagesjsii_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersAcerDesktopAWS DevopsCDKcdkcdk_stack.py", line 134, in __init__
    target_group = elbv2.ApplicationTargetGroup(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:Program FilesPython312Libsite-packagesjsii_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:Program FilesPython312Libsite-packagesaws_cdkaws_elasticloadbalancingv2__init__.py", line 22906, in __init__
    jsii.create(self.__class__, self, [scope, id, props])
  File "C:Program FilesPython312Libsite-packagesjsii_kernel__init__.py", line 334, in create
    response = self.provider.create(
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:Program FilesPython312Libsite-packagesjsii_kernelprovidersprocess.py", line 365, in create
    return self._process.send(request, CreateResponse)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:Program FilesPython312Libsite-packagesjsii_kernelprovidersprocess.py", line 342, in send
    raise RuntimeError(resp.error) from JavaScriptError(resp.stack)
RuntimeError: Passed to parameter props of new aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationTargetGroup: Unable to deserialize value as aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationTargetGroupProps | undefined
├── 🛑 Failing value is an object
│      { '$jsii.struct': [Object] }
╰── 🔍 Failure reason(s):
    ╰─ Key 'targets': Unable to deserialize value as array<aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationLoadBalancerTarget> | undefined
        ├── 🛑 Failing value is an array
        │      [ '${Token[TOKEN.111]}', '${Token[TOKEN.137]}' ]
        ╰── 🔍 Failure reason(s):
            ╰─ Index 0: Unable to deserialize value as aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationLoadBalancerTarget
                ├── 🛑 Failing value is a string
                │      '${Token[TOKEN.111]}'
                ╰── 🔍 Failure reason(s):
                    ╰─ Value does not have the "$jsii.byref" key

THIS IS MY ACTUAL CODE

alb = elbv2.ApplicationLoadBalancer(
    self,
    "MyALB",
    vpc=vpc,
    internet_facing=True,
    security_group=sec_group,
    load_balancer_name="MyALB",
)

# Add Listener to ALB
listener = alb.add_listener(
    "Listener",
    port=80,
    open=True,
)

target_group = elbv2.ApplicationTargetGroup(
    self,
    "TargetGroup",
    vpc=vpc,
    port=80,
    targets=[instance1.instance_id, instance2.instance_id],
    health_check=elbv2.HealthCheck(
        path="/",
        interval=Duration.seconds(60)
    )
)

listener.add_targets(
    "ListenerTargetGroup",
    target_groups=[target_group]
)

# Output the ALB DNS Name
CfnOutput(self, "LoadBalancerDNS", value=alb.load_balancer_dns_name)

2

Answers


  1. The targets prop in ApplicationTargetGroup expects a list of IApplicationLoadBalancerTarget, and you’re passing a list of strings.

    Use InstanceTarget:

    target_group = elbv2.ApplicationTargetGroup(
        self,
        "TargetGroup",
        ...
        targets=[
            elbv2_targets.InstanceTarget(instance1),
            elbv2_targets.InstanceTarget(instance2),
        ],
        ...
    )
    
    Login or Signup to reply.
  2. I think that you must define your instance with instanceTarget

    https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2_targets.InstanceTarget.html

        # Add Target Group to Listener
        target_group = listener.add_targets(
            "ListenerTargetGroup",
            port=80,
            targets=[
                elbv2_targets.InstanceIdTarget(instance1.instance_id),
                elbv2_targets.InstanceIdTarget(instance2.instance_id)
            ],
            health_check=elbv2.HealthCheck(
                path="/",
                interval=Duration.seconds(60)
            )
        )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search