EndpointConnectionError with XRay daemon in ECS tasks

0

I've created an ECS Service with a task definition that contains two containers. The first is the xray-daemon, and the second is my application (Python, Flask). The task starts fine; however, the application container gives me the following error in the logs.

botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "http://127.0.0.1:2000/GetSamplingRules"

I've tried to do a port mapping on the xray-daemon container to 2000/tcp and followed the documentation to link the two containers specified here.

Any suggestions/thoughts on how to fix this?

Below is my task definition:

{
    "family": "app-api",
    "containerDefinitions": [
	    {
	      "name": "xray-daemon",
	      "image": "public.ecr.aws/xray/aws-xray-daemon:latest",
	      "cpu": 32,
	      "memoryReservation": 256,
              "environment": [
                  {
                      "name": "AWS_REGION",
                      "value": "us-east-1"
                  }
              ],
              "logConfiguration": {
                  "logDriver": "awslogs",
                  "options": {
                      "awslogs-group": "/ecs/aws-xray-daemon-app-api",
                      "awslogs-region": "us-east-1",
                      "awslogs-stream-prefix": "ecs"
                  }
              },
	      "portMappings" : [
		  {
		      "hostPort": 0,
		      "containerPort": 2000,
		      "protocol": "udp"
		  },
		  {
		      "hostPort": 0,
		      "containerPort": 2000,
		      "protocol": "tcp"
		  }
	       ]
	    },
        {
            "name": "app-api",
            "image": "XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/app-api:latest",
            "cpu": 0,
	      "environment": [
		  { "name" : "AWS_REGION", "value" : "us-east-1" },
		  { "name" : "NOTIFICATION_TOPIC", "value" : "arn:aws:sns:us-east-1:XXXXXXXXXXXX:app-api" },
		  { "name" : "AWS_XRAY_DAEMON_ADDRESS", "value" : "xray-daemon:2000" }
	      ],
            "portMappings": [
                {
                    "containerPort": 5000,
                    "hostPort": 8082,
                    "protocol": "tcp"
                }
            ],
            "links":["xray-daemon"],
            "essential": true,
            "environment": [],
            "mountPoints": [],
            "volumesFrom": [],
            "logConfiguration": {
                "logDriver": "awslogs",
                "options": {
                    "awslogs-group": "/ecs/app-api",
                    "awslogs-region": "us-east-1",
                    "awslogs-stream-prefix": "ecs"
                }
            }
        }
    ],
    "networkMode": "bridge",
    "requiresCompatibilities": [
        "EXTERNAL"
    ],
    "taskRoleArn": "arn:aws:iam::XXXXXXXXXXXX:role/rol_XXXXXXXXXXXX",
    "executionRoleArn": "arn:aws:iam::XXXXXXXXXXXX:role/rol_XXXXXXXXXXXX",
    "cpu": "1024",
    "memory": "1024"
}
profile picture
asked 10 months ago316 views
1 Answer
0
Accepted Answer

I was able to solve it. This was an error in the task definition where I had two key/values for environment in the application's container definition. The last environment key was overwriting the first environment key/values.

I removed the second "environment": [], in the task definition and redeployed my task, and everything works now.

profile picture
answered 10 months ago
profile pictureAWS
EXPERT
reviewed 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions