python - 无法从 boto3 注册 ECS 任务
问题描述
我正在尝试创建一个可以通过任何 AWS 帐户运行的基本云基础设施。我正在使用 python boto3 模块来创建集群、任务定义和服务,这些都是从我的代码中成功创建的。但是,该任务未从我的服务运行,当我检查事件时,我可以看到错误“服务 my_service 无法放置任务,因为没有容器实例满足其所有要求。原因:在您的集群中未找到任何容器实例'。
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 实例内部更改任何内容)。如何运行任务?
解决方案
推荐阅读
- mysql - MariaDB 主到主复制自动增量不是顺序的
- ios - 我的应用程序在 ios14 上崩溃 应用程序在闪屏上崩溃?
- python - 在 Pandas 中将多列分组为一列
- java - 如何在使用 SpringExtension 进行所有测试之前/之后使用上下文执行一些代码?
- laravel - 在 Laravel 7 中找不到类
- java - jaxb 按类型解组到对象
- kubernetes - 我们可以有一个没有弹性搜索的中央 kibana 吗?
- javascript - 在 chrome 扩展中访问网络摄像头 - DOMException:权限被拒绝
- swiftui - SwiftUI NavigationLink navigationBarHidden 与工作表闪烁屏幕
- python - 如何在具有相同 XPath 的多个元素上使用 click()?