确保您的ECS集群已配置EC2容量提供程序。您可以在AWS控制台中导航到ECS集群,然后单击“容量提供程序”选项卡以进行配置。
确保您的任务定义中指定了使用EC2容量提供程序。您可以在任务定义JSON文件中使用以下代码段来指定使用EC2容量提供程序:
{
"executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
"containerDefinitions": [{
"name": "mycontainer",
"image": "myimage",
"cpu": 1024,
"memory": 2048,
"portMappings": [{
"containerPort": 80,
"hostPort": 80
}]
}],
"requiresCompatibilities": [
"EC2"
],
"networkMode": "bridge",
"memory": "512",
"cpu": "256"
}
有关更多信息,请参阅Amazon Elastic Container Service Developer Guide。