如果您通过任务定义启用“Auto-configure CloudWatch Logs”功能,则可能会看到以下警告:
WARNING at x.y.z: Task definition with auto-configure CloudWatch logs has no container with the requested name
原因是因为启用了上述功能且容器名称与请求的名称不匹配。解决此问题的一种方法是为任务定义中的每个容器设置唯一的名称,并确保CloudWatch日志组的名称与该容器的名称匹配。以下是一个简单的任务定义的示例:
{
"family": "my-task",
"containerDefinitions": [
{
"name": "container-1",
"image": "my-repo/container-1",
// other container properties
},
{
"name": "container-2",
"image": "my-repo/container-2",
// other container properties
}
],
"executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
// other task definition properties
}
在此示例中, container-1
和 container-2
是唯一的容器名称。如果您选择启用 Auto-configure CloudWatch Logs
,则必须将日志组名称设置为唯一的容器名称:
{
"containerDefinitions": [
{
"name": "container-1",
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "container-1",
"awslogs-region": "us-east-1"
}
}
},
{
"name": "container-2",
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "container-2",
"awslogs-region": "us-east-1"
}
}
}
]
}
通过使用唯一的容器名称和在任务定义中显式定义CloudWatch日志组,可以解