in packages/@aws-cdk/toolkit-lib/lib/context-providers/load-balancers.ts [106:150]
public async getListener(): Promise<LoadBalancerListenerContextResponse> {
if (this.listener) {
try {
const loadBalancer = await this.getLoadBalancer();
return {
listenerArn: this.listener.ListenerArn!,
listenerPort: this.listener.Port!,
securityGroupIds: loadBalancer.SecurityGroups || [],
};
} catch (err) {
throw new ContextProviderError(`No associated load balancer found for listener arn ${this.filter.listenerArn}`);
}
}
const loadBalancers = await this.getLoadBalancers();
if (loadBalancers.length === 0) {
throw new ContextProviderError(
`No associated load balancers found for load balancer listener query ${JSON.stringify(this.filter)}`,
);
}
const listeners = (await this.getListenersForLoadBalancers(loadBalancers)).filter((listener) => {
return (
(!this.filter.listenerPort || listener.Port === this.filter.listenerPort) &&
(!this.filter.listenerProtocol || listener.Protocol === this.filter.listenerProtocol)
);
});
if (listeners.length === 0) {
throw new ContextProviderError(`No load balancer listeners found matching ${JSON.stringify(this.filter)}`);
}
if (listeners.length > 1) {
throw new ContextProviderError(
`Multiple load balancer listeners found matching ${JSON.stringify(this.filter)} - please provide more specific criteria`,
);
}
return {
listenerArn: listeners[0].ListenerArn!,
listenerPort: listeners[0].Port!,
securityGroupIds:
loadBalancers.find((lb) => listeners[0].LoadBalancerArn === lb.LoadBalancerArn)?.SecurityGroups || [],
};
}