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
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 usinglocalhost
. In other words if you try to reachlocalhost:9201
from any other container in the same task you will end up talking to your promscale container.