1

I'm trying to setup an AWS ECS cluster which has a single task that has 3 separate containers for prometheus, promscale, and prometheus-ecs-discovery.

I'm trying to figure out how to dynamically set the env var PROMSCALE_HOSTNAME in my prometheus container to either the hostname or ip of the promscale container as i'm ultimately using this value in a config file so that the prometheus container can talk to the promscale container.

Is there any way to do this or do I have to create a load balancer in my VPC to handle this?

PrometheusTask:
    Type: AWS::ECS::TaskDefinition
    Properties:
      Family: !Sub "${Stage}-prometheus"
      ContainerDefinitions:
        - Name: !Sub "${Stage}-prometheus-container"
          Image: myorg/prometheus:latest
          Environment:
            - Name: STAGE
              Value: !Ref Stage
            - Name: PROMSCALE_HOSTNAME # <-- I WANT THIS VALUE TO BE THE HOSTNAME OR IP OF THE PROMSCALE CONTAINER
              Value: !Sub "${Stage}-promscale-container"
        - Name: !Sub "${Stage}-prometheus-ecs-discovery-container"
          Image: myorg/prometheus-ecs-discovery:latest
          Environment:
            - Name: AWS_REGION
              Value: !Ref AWS::Region
        - Name: !Sub "${Stage}-promscale-container"
          Image: myorg/promscale:latest
          PortMappings:
            - ContainerPort: 9201

Catfish
  • 227
  • 1
  • 11

1 Answers1

6

If you are using the awsvpc networking mode for your task (which would be a good idea) your task will basically have a single network name space. This means you can reach all of your containers using localhost. In other words if you try to reach localhost:9201 from any other container in the same task you will end up talking to your promscale container.

mreferre
  • 426
  • 1
  • 5
  • 1
    You're right that worked. – Catfish Apr 28 '21 at 14:22
  • This is not such a good idea if your ECS Tasks are running on EC2 instead of Fargate. EC2 instances have a (very) limited number of available ENIs per host. – Philip Couling Jun 06 '22 at 17:23
  • I would not say "it's not a good idea" in absolute terms. It's a consideration you need to make. ECS has also introduced [trunking support](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-instance-eni.html) to mitigate this potential concern. – mreferre Jun 08 '22 at 07:46