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

fix(aws-elasticloadbalancingv2-targets): add AlbListenerTarget for NLBs, deprecate AlbTarget due to ALB listener race conditions #17248

Conversation

jamesorlakin
Copy link
Contributor

@jamesorlakin jamesorlakin commented Oct 31, 2021

This PR replaces AlbTarget with AlbListenerTarget, allowing us to automatically add a dependency between the provided ALB listener and the associated NLB target group. Without such a dependency stacks may fail to deploy if the listener is not created when the target group attempts to be created.

  • ALB listeners did not have a public port and protocol property, is this explicitly by design? (And would making it public be an issue?)
    • Having them public means we can use the port from the listener directly
  • While AlbTarget could have logic added to it to add dependencies, this would not work if the provided ALB doesn't have any items in its listener property (e.g. new ApplicationListener(...) instead of alb.addListener(...)). I felt deprecating is the safer and clearer path here. Alternatively warnings could be added for such a scenario?

Closes #17208


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…Bs, deprecate AlbTarget due to ALB listener race conditions
@gitpod-io
Copy link

gitpod-io bot commented Oct 31, 2021

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: d483e0d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jamesorlakin jamesorlakin marked this pull request as ready for review October 31, 2021 12:06
Copy link
Contributor

@njlynch njlynch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I have a few minor points to adjust, otherwise I think the approach is reasonable enough.

*/
private readonly certificateArns: string[];
public readonly protocol: ApplicationProtocol;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear why protocol was exposed; simply for the tests? The tests are already checking this via the CloudFormation checks (Protocol: 'HTTPS',).

@@ -25,6 +25,7 @@ describe('tests', () => {
expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::Listener', {
Protocol: 'HTTPS',
});
expect(listener.protocol).toBe(elbv2.ApplicationProtocol.HTTPS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit redundant, given the above expect.

* @param alb The application load balancer to load balance to
* @param port The port on which the target is listening
*
* @deprecated Use AlbListenerTarget instead. This target does not automatically
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to deprecate both the class and constructor; the latter will effectively deprecate the former. Can you move this more descriptive deprecation message to the top class-level?

@@ -23,7 +24,7 @@ export class AlbArnTarget implements elbv2.INetworkLoadBalancerTarget {
return this.attach(targetGroup);
}

private attach(_targetGroup: elbv2.ITargetGroup): elbv2.LoadBalancerTargetProps {
protected attach(_targetGroup: elbv2.ITargetGroup): elbv2.LoadBalancerTargetProps {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~ (Nit) - An alternative would be to make this public _attach and mark it as @internal. That would prevent it showing up in the docs and (potentially) confusing people who think they should be using it directly.

@njlynch njlynch added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Nov 29, 2021
@github-actions github-actions bot added closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Nov 29, 2021
@github-actions github-actions bot closed this Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-elasticloadbalancingv2-targets closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while.
Projects
None yet
3 participants