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

NetworkLoadBalancedFargateService to support listener other than tcp80 #4793

Closed
1 task
pahud opened this issue Oct 31, 2019 · 2 comments · Fixed by #4825
Closed
1 task

NetworkLoadBalancedFargateService to support listener other than tcp80 #4793

pahud opened this issue Oct 31, 2019 · 2 comments · Fixed by #4825
Assignees
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library feature-request A feature should be added or improved. in-progress This issue is being actively worked on.

Comments

@pahud
Copy link
Contributor

pahud commented Oct 31, 2019

At this moment NetworkLoadBalancedFargateService is extending NetworkLoadBalancedServiceBase, which only support listener on tcp80.

this.listener = this.loadBalancer.addListener('PublicListener', { port: 80 });

Please support different port other than 80.

Use Case

For some TCP application running on Fargate behind NLB, it's very common to listen on port other than 80.

Proposed Solution

Add a listenerPort property for NetworkLoadBalancedServiceBaseProps.

export interface NetworkLoadBalancedServiceBaseProps {
/**
* The name of the cluster that hosts the service.
*
* If a cluster is specified, the vpc construct should be omitted. Alternatively, you can omit both cluster and vpc.
* @default - create a new cluster; if both cluster and vpc are omitted, a new VPC will be created for you.
*/
readonly cluster?: ICluster;
/**
* The VPC where the container instances will be launched or the elastic network interfaces (ENIs) will be deployed.
*
* If a vpc is specified, the cluster construct should be omitted. Alternatively, you can omit both vpc and cluster.
* @default - uses the VPC defined in the cluster or creates a new VPC.
*/
readonly vpc?: IVpc;
/**
* The properties required to create a new task definition. One of taskImageOptions or taskDefinition must be specified.
*
* @default - none
*/
readonly taskImageOptions?: NetworkLoadBalancedTaskImageOptions;
/**
* Determines whether the Load Balancer will be internet-facing.
*
* @default true
*/
readonly publicLoadBalancer?: boolean;
/**
* The desired number of instantiations of the task definition to keep running on the service.
*
* @default 1
*/
readonly desiredCount?: number;
/**
* The domain name for the service, e.g. "api.example.com."
*
* @default - No domain name.
*/
readonly domainName?: string;
/**
* The Route53 hosted zone for the domain, e.g. "example.com."
*
* @default - No Route53 hosted domain zone.
*/
readonly domainZone?: IHostedZone;
/**
* The name of the service.
*
* @default - CloudFormation-generated name.
*/
readonly serviceName?: string;
/**
* The period of time, in seconds, that the Amazon ECS service scheduler ignores unhealthy
* Elastic Load Balancing target health checks after a task has first started.
*
* @default - defaults to 60 seconds if at least one load balancer is in-use and it is not already set
*/
readonly healthCheckGracePeriod?: cdk.Duration;
/**
* The network load balancer that will serve traffic to the service.
*
* [disable-awslint:ref-via-interface]
*
* @default - a new load balancer will be created.
*/
readonly loadBalancer?: NetworkLoadBalancer;
/**
* Specifies whether to propagate the tags from the task definition or the service to the tasks in the service.
* Tags can only be propagated to the tasks within the service during service creation.
*
* @default - none
*/
readonly propagateTags?: PropagatedTagSource;
/**
* Specifies whether to enable Amazon ECS managed tags for the tasks within the service. For more information, see
* [Tagging Your Amazon ECS Resources](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-using-tags.html)
*
* @default false
*/
readonly enableECSManagedTags?: boolean;
/**
* The options for configuring an Amazon ECS service to use service discovery.
*
* @default - AWS Cloud Map service discovery is not enabled.
*/
readonly cloudMapOptions?: CloudMapOptions;
}

Other

  • [v] 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@pahud pahud added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 31, 2019
@SomayaB SomayaB added the @aws-cdk/aws-ecs-patterns Related to ecs-patterns library label Oct 31, 2019
@piradeepk
Copy link
Contributor

@pahud the loadBalancer is exposed to the user. You are able to add a new listener with a different port if you choose to listen on a different port.

@piradeepk piradeepk removed the needs-triage This issue or PR still needs to be triaged. label Oct 31, 2019
@pahud
Copy link
Contributor Author

pahud commented Nov 1, 2019

Hi @pkandasamy91

Yes it's possible. But then I need to specify another listener and specify targetgroup for this listener and I probably need to remove the default one on TCP80?

Why not just provide a defaultListenerPort like this and, if provided, override the default tcp 80?

In this case, we just need to add an optional property for it and that's all.

    const svc = new ecsPatterns.NetworkLoadBalancedFargateService(this, 'NLBService', {
      assignPublicIp: true,
      cluster,
      defaultListenerPort: 6032,
      taskImageOptions: {
        image: ecs.ContainerImage.fromAsset('./dockerAssets.d'),
        enableLogging: true,
        containerPort: 6032
      }
    })

@SomayaB SomayaB added the in-progress This issue is being actively worked on. label Nov 4, 2019
@mergify mergify bot closed this as completed in #4825 Nov 7, 2019
mergify bot pushed a commit that referenced this issue Nov 7, 2019
…cation load balanced services (#4825)

* - feat(ecs-patterns): allow to specify different NLB listener port other than the default 80(fix #4793)
- feat(ecs-patterns): public facing NLB fronted fargate tasks with assignPublicIp enabled should allow all ipv4 traffic to the ingress port on the fargate task

* - support ApplicationLoadBalancedServiceBase as well
- remove non-related logic to another PR

* minor fix

* minor fix

* minor fix

* add the testing

* add more tests:

✔ setting NLB special listener port to create the listener
✔ setting ALB special listener port to create the listener
✔ setting ALB HTTPS protocol to create the listener on 443
✔ setting ALB HTTP protocol to create the listener on 80
✔ setting ALB without any protocol or listenerPort to create the listener on 80

* minor lint fix

* minor fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library feature-request A feature should be added or improved. in-progress This issue is being actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants