Reputation: 25
I'm trying to get a load balancer ARN that is created by CDK
Load balancer is created using
lb = lbv2.CfnLoadBalancer(self, "LB",
name = config.loadbalancer.name,
scheme= "internet-facing",
security_groups=[core.Fn.ref(config.loadbalancer.sgname)],
subnets = [public_subnets[0],public_subnets[1]],
type = config.loadbalancer.type
)
Trying to retrieve the ARN for load balancer and listener group
lb_listeners= lbv2.CfnListener(self, "LBlisteners",
default_actions = [{"Type":"forward","TargetGroupArn":target_groups.listenerArn, "Order" : 1}],
load_balancer_arn = core.Fn.ref("Lb"))
Both method is failing target_groups.listenerArn
and referrig it back using core.Fn.ref("Lb")
Upvotes: 0
Views: 1980
Reputation: 2400
the Cfn Functions generally do not have all the same hooks as fully fleshed out cdk constructs. Cfn (meaning CloudFormation) are escape hatches that are used to put things in CDK that haven't been developed for CDK yet, and are pretty much just straight pushes. That is a caveat to say that you cannot expect any construct you have to use cfn with to work with every other construct - the hooks simply aren't there.
First off, as it appears you are using Python, its usually {construct}_arn like table_arn or function_arn. (snake case)
Second, if you have a decent linter and intelli-sense, it should pop a list of potential attributes when you put the dot down. You should be able to do a partial match and arn will be one.
Finally, the cdk documentation says it pretty clearly: https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_elasticloadbalancingv2/CfnListener.html#aws_cdk.aws_elasticloadbalancingv2.CfnListener.attr_listener_arn
so in effect, you probably will need to use:
lb_listeners= lbv2.CfnListener(self, "LBlisteners",
default_actions = [{"Type":"forward","TargetGroupArn":target_groups.listenerArn, "Order" : 1}],
load_balancer_arn = lb.attr_listener_arn)
(core.Fn.ref() is another escape hatch function that should generally only be used when getting really into the nitty gritty of unfinished constructs)
Upvotes: 4