Skip to content

Load Balanced Web Service: incompatibility when nlb and sidecars are used together #3768

@mygzi

Description

@mygzi

Specifying nlb with a sidecar generates a cf template with the same ContainerPort in multiple ContainerDefinitions sections, which is an invalid configuration. When attempting to deploy the example service below, the following error is returned:

Resource handler returned message: "Invalid request provided: Create TaskDefinition: TCP container port '9901' is used multiple times in task when networkMode=awsvpc.

name: sidecar-with-nlb
type: Load Balanced Web Service

http: false

nlb:
  port: 80/tcp
  target_container: envoy

# Configuration for your containers and service.
image:
  location: public.ecr.aws/hashicorp/envoy-alpine:latest
  port: 10000

cpu: 256       # Number of CPU units for the task.
memory: 512    # Amount of memory in MiB used by the task.
count: 1       # Number of tasks that should be running in your service.
exec: true     # Enable running commands in your container.

sidecars:
  envoy:
    # envoy admin port
    port: 9901
    image: public.ecr.aws/hashicorp/envoy-alpine:latest

Here is an excerpt from the cf template provided by copilot svc package

      ContainerDefinitions:
        - Name: !Ref WorkloadName
          Image: !Ref ContainerImage

          PortMappings:
            - ContainerPort: !Ref ContainerPort
            - ContainerPort: 9901
              Protocol: tcp

It appears that the cf partial below is not sidecar aware, and assumes that the nlb target is always the main workload container.

{{if ne .NLB.Listener.TargetPort .NLB.MainContainerPort}} {{/*No need to add additional port if the target port is the same as image port*/}}

For now we are working around this with a task override as follows:

taskdef_overrides:
  - path: ContainerDefinitions[0].PortMappings
    value:
      - ContainerPort: !Ref ContainerPort
        Protocol: tcp

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/sidecarIssues about sidecar containers.type/bugIssues that are bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions