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

Does ApplicationLoadBalancedFargateService support task definitions with multiple containers/ports? #5506

Closed
lbjay opened this issue Dec 20, 2019 · 3 comments
Assignees
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library guidance Question that needs advice or information.

Comments

@lbjay
Copy link

lbjay commented Dec 20, 2019

❓ General Issue

The Question

I'm trying to create a fargate service which has an app container on port 8080 and an nginx reverse proxy container on port 443. The resulting load balancer target registration always ends up using port 8080 instead of what I want, port 443.

Environment

  • CDK CLI Version: 1.19.0 (build 5597bbe)
  • Module Version: aws-ecs-patterns v1.19.0
  • Language: TypeScript

Other information

Example of how i'm creating the service:

    const taskDefinition = new FargateTaskDefinition(this, 'TaskDefinition');

    const appContainer = new ContainerDefinition(this, 'AppContainer', {
      image: ContainerImage.fromRegistry(APP_IMAGE),
      taskDefinition,
    });
    appContainer.addPortMappings({
      hostPort: 8080,
      containerPort: 8080
    });
    const proxyContainer = new ContainerDefinition(this, 'ProxyContainer', {
      image: ContainerImage.fromRegistry(PROXY_IMAGE),
      taskDefinition,
    })
    proxyContainer.addPortMappings({
      hostPort: 443,
      containerPort: 443,
    });

    const certificate = Certificate.fromCertificateArn(this, 'cert', CERTIFICATE_ARN);
    const service = new ApplicationLoadBalancedFargateService(this, 'service', {
      cluster,
      taskDefinition,
      certificate,
      domainName: '...',
      domainZone: HostedZone.fromHostedZoneAttributes(this, 'zone', { ... }),
      listenerPort: 443,
    })

What cdk synth produces for the service (note the "ContainerPort": 8080,):

    "serviceService8587F09F": {
      "Type": "AWS::ECS::Service",
      "Properties": {
        "Cluster": {
          "Ref": "ClusterEB0386A7"
        },
        "DeploymentConfiguration": {
          "MaximumPercent": 200,
          "MinimumHealthyPercent": 50
        },
        "DesiredCount": 1,
        "EnableECSManagedTags": false,
        "HealthCheckGracePeriodSeconds": 60,
        "LaunchType": "FARGATE",
        "LoadBalancers": [
          {
            "ContainerName": "AppContainer",
            "ContainerPort": 8080,
            "TargetGroupArn": {
              "Ref": "serviceLBPublicListenerECSGroupD194ED9A"
            }
          }
        ],
        "NetworkConfiguration": {
          "AwsvpcConfiguration": {
            "AssignPublicIp": "DISABLED",
            "SecurityGroups": [
              {
                "Fn::GetAtt": [
                  "serviceServiceSecurityGroup94D21C42",
                  "GroupId"
                ]
              }
            ],
            "Subnets": [
              {
                "Ref": "VpcPrivateSubnet1Subnet536B997A"
              },
              {
                "Ref": "VpcPrivateSubnet2Subnet3788AAA1"
              }
            ]
          }
        },
        "TaskDefinition": {
          "Ref": "TaskDefinitionB36D86D9"
        }
      },
      "DependsOn": [
        "serviceLBPublicListenerECSGroupD194ED9A",
        "serviceLBPublicListener924DC596"
      ],
      "Metadata": {
        "aws:cdk:path": "CdkFargateElbStack/service/Service/Service"
      }
    },
@lbjay lbjay added the needs-triage This issue or PR still needs to be triaged. label Dec 20, 2019
@piradeepk
Copy link
Contributor

piradeepk commented Dec 20, 2019

@lbjay Great question! ApplicationLoadBalancedFargateService does not directly allow users to use taskdefinitions with multiple port mappings. You can create an ApplicationLoadBalancedFargateService and then add port mappings and add a new listener to the load balancer.

We recently merged in a new pattern which supports multiple target groups/port mappings https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-ecs-patterns/lib/fargate/application-multiple-target-groups-fargate-service.ts

@piradeepk piradeepk added guidance Question that needs advice or information. @aws-cdk/aws-ecs-patterns Related to ecs-patterns library and removed needs-triage This issue or PR still needs to be triaged. labels Dec 20, 2019
@piradeepk
Copy link
Contributor

@lbjay Please let us know if this does not solve your issue.

@lbjay
Copy link
Author

lbjay commented Jan 15, 2020

Thanks! It turns out #4107 (just landed in v1.2.0) was exactly what I needed.

@lbjay lbjay closed this as completed Jan 15, 2020
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 guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

3 participants