我有一个配置为使用awsvpc网络模式的任务定义。 根据{{3}}:
awsvpc网络模式仅支持专用子网。 由于任务不接收公共IP地址,因此NAT网关是 出站互联网访问和入站互联网流量所需 应该通过负载均衡器进行路由。
我在公共子网(具有Internet网关)中设置了NAT网关,并在私有子网中配置了路由表,以将流量发送到NAT网关。但是,当我想创建一个驻留在专用子网中的任务时,会得到:
Run tasks failed Reasons : ["ATTRIBUTE"]. Learn more
如果我选择EC2本身使用的公共子网,它将创建任务。但是我无法在任务中访问Internet。
我的最终目标是从EC2中的任务访问Internet。
更新:我的任务定义:
{
"ipcMode": null,
"executionRoleArn": "arn:aws:iam::783294628224:role/ecsTaskExecutionRole",
"containerDefinitions": [
{
"dnsSearchDomains": null,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/TEST-Task-Definition",
"awslogs-region": "us-west-2",
"awslogs-stream-prefix": "ecs"
}
},
"entryPoint": null,
"portMappings": [
{
"hostPort": 8500,
"protocol": "tcp",
"containerPort": 8500
},
{
"hostPort": 8501,
"protocol": "tcp",
"containerPort": 8501
}
],
"command": null,
"linuxParameters": null,
"cpu": 0,
"environment": [],
"resourceRequirements": null,
"ulimits": null,
"dnsServers": null,
"mountPoints": [],
"workingDirectory": null,
"secrets": null,
"dockerSecurityOptions": null,
"memory": null,
"memoryReservation": 500,
"volumesFrom": [],
"stopTimeout": null,
"image": "<MY ECR REPOSITORY ADDRESS FOR IMAGE 1>",
"startTimeout": null,
"dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"pseudoTerminal": null,
"user": "root",
"readonlyRootFilesystem": null,
"dockerLabels": null,
"systemControls": null,
"privileged": true,
"name": "backend"
},
{
"dnsSearchDomains": null,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/TEST-Task-Definition",
"awslogs-region": "us-west-2",
"awslogs-stream-prefix": "ecs"
}
},
"entryPoint": null,
"portMappings": [
{
"hostPort": 80,
"protocol": "tcp",
"containerPort": 80
}
],
"command": null,
"linuxParameters": null,
"cpu": 0,
"environment": [],
"resourceRequirements": null,
"ulimits": null,
"dnsServers": null,
"mountPoints": [],
"workingDirectory": null,
"secrets": null,
"dockerSecurityOptions": null,
"memory": null,
"memoryReservation": 500,
"volumesFrom": [],
"stopTimeout": null,
"image": "<MY ECR REPOSITORY ADDRESS FOR IMAGE 2>",
"startTimeout": null,
"dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"pseudoTerminal": null,
"user": "root",
"readonlyRootFilesystem": null,
"dockerLabels": null,
"systemControls": null,
"privileged": true,
"name": "frontend"
}
],
"memory": null,
"taskRoleArn": "arn:aws:iam::783294628224:role/ecsTaskExecutionRole",
"family": "TEST-Task-Definition",
"pidMode": null,
"requiresCompatibilities": [
"EC2"
],
"networkMode": "awsvpc",
"cpu": null,
"proxyConfiguration": null,
"volumes": [],
"placementConstraints": []
}
答案 0 :(得分:0)
如果您不使用https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html
确保已将座席参数环境密钥ECS_ENABLE_TASK_ENI
设置为true
答案 1 :(得分:0)
我终于成功解决了我的问题。据我所知,在“任务定义”中使用awsvpc
网络模式时,必须在EC2子网中创建任务(或服务)。另外,如果您希望您的任务可以访问Internet,则应在另一个子网中创建NAT网关,该子网具有到位于VPC中的Internet网关的默认路由。在任务/服务/ EC2子网中,您必须向NAT网关添加默认路由。发生的唯一问题是您不能再使用SSH了。如果您想使用EC2,我认为您应该设置负载均衡器。