Thread
#general
    s

    stocky-wire-60053

    1 month ago
    Good morning and good day to all; I'm trying to deploy a Fargate cluster for a FastAPI Python app, using instructions pretty close to Pulumi's user-docs example, but I get the following error;
    ClientException: When networkMode=awsvpc, the host ports and container ports in port mappings must match
    . (I'll post code in the reply as to not clutter here.)
    cluster = aws.ecs.Cluster("myapp-cluster")
        repo = awsx.ecr.Repository("myapp-ecr")
        image = awsx.ecr.Image("myapp", repository_url=repo.url, path="../")
        lb = awsx.lb.ApplicationLoadBalancer("myapp-lb")
        
        
        service = awsx.ecs.FargateService("myapp-service",
                                          cluster=cluster.arn,
                                          desired_count=2,
                                          task_definition_args=awsx.ecs.FargateServiceTaskDefinitionArgs(
                                              container=awsx.ecs.TaskDefinitionContainerDefinitionArgs(
                                                  image=image.image_uri,
                                                  cpu=512,
                                                  memory=128,
                                                  essential=True,
                                                  port_mappings=[awsx.ecs.TaskDefinitionPortMappingArgs(
                                                      host_port=8080,
                                                      container_port=8080,
                                                      target_group=lb.default_target_group
                                                  )],
                                              )
                                          )
                                          )
        pulumi.export("url", lb.load_balancer.dns_name)
    FROM python:3.9
        
        RUN mkdir -p /myapp/src/myapp
        COPY setup.cfg setup.py /myapp/
        COPY src/ /myapp/src/
        
        RUN python3 -m venv "/myapp/venv" \
            && /myapp/venv/bin/python -m pip install --upgrade pip \
            && /myapp/venv/bin/python -m pip install -e /myapp/
        
        RUN chown root:root -R /myapp
        RUN chown root:root -R /myapp/venv
        
        EXPOSE 8080
        
        ENV PATH="/myapp/venv/bin:$PATH"
        CMD python -m uvicorn main:app --host 0.0.0.0 --port 8080 --app-dir /myapp/src/myapp/
    In my port mappings, I've set the host and container ports to be the same, so I'm clearly missing something.
    b

    billowy-army-68599

    1 month ago
    I saw your stackoverflow question, I’ll debug this later. I think it might be an issue with the awsx implementation, but can’t be sure
    @stocky-wire-60053 unfortunately this is a bug. I’ve filed: https://github.com/pulumi/pulumi-awsx/issues/894 Once I have a workaround I’ll update the stackoverflow with an answer
    s

    stocky-wire-60053

    1 month ago
    Very thorough of you, thank you muchly : )
    m

    most-jordan-25674

    1 month ago
    I was able to deploy to ECS Fargate using AWS classic so if can’t wait for the fix then that is a possibility.
    s

    stocky-wire-60053

    1 month ago
    Assigning my docker container to listen on port-80 seems to work -- I'm not certain if that is a bad practice?