Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法从boto3注册ECS任务_Python_Amazon Web Services_Boto3 - Fatal编程技术网

Python 无法从boto3注册ECS任务

Python 无法从boto3注册ECS任务,python,amazon-web-services,boto3,Python,Amazon Web Services,Boto3,我正在尝试创建一个可以通过任何AWS帐户运行的基本云基础设施。我正在使用python boto3模块创建集群、任务定义和服务,这些都是从我的代码中成功创建的。但是,任务没有从我的服务运行,当我检查事件时,我可以看到错误“服务我的服务无法放置任务,因为没有容器实例满足其所有要求。原因:在群集“中未找到容器实例 import boto3 client = boto3.client('ecs') cluster_response = client.create_cluster( cluster

我正在尝试创建一个可以通过任何AWS帐户运行的基本云基础设施。我正在使用python boto3模块创建集群、任务定义和服务,这些都是从我的代码中成功创建的。但是,任务没有从我的服务运行,当我检查事件时,我可以看到错误“服务我的服务无法放置任务,因为没有容器实例满足其所有要求。原因:在群集“中未找到容器实例

import boto3
client = boto3.client('ecs')
cluster_response = client.create_cluster(
    clusterName='my_cluster',
)
print(cluster_response)

taskdef_response = client.register_task_definition(
    family = 'my_taskdef',
    containerDefinitions=[
        {
            'name': 'my_taskdef',
            'image': '****/sample:latest'
        }
    ],
    memory='256',
    cpu='1024',
    taskRoleArn='ecsTaskExecutionRole'
)
print(taskdef_response)
service_response = client.create_service(
    cluster='my_cluster',
    serviceName='my_service',
    taskDefinition='my_taskdef',
    desiredCount=1,
    launchType='EC2'
)
print(service_response)

我希望它在服务生成的任务中运行我的docker映像。AWS帐户没有任何现有的EC2实例,我想运行一个任务,从这段代码创建EC2实例(无需从EC2实例内部更改任何内容)。如何运行任务?

如果找到解决方案,请与我们分享。@BikeshM我在没有ECS的情况下采用了不同的方法。但这个错误是因为它缺少一部分。代码还需要一个新的
ecs优化
实例,并附加
AmazoneC2ContainerServiceForec2OLE
策略。