一个面向对象的友好的pythonic客户端,用于amazon web服务(aws)
OOWS的Python项目详细描述
oows
警告-此项目正在早期开发中。欢迎投稿和反馈。不鼓励在生产系统中使用
oows(oh owls)是一个面向对象的amazon web服务友好客户端-aws。它基于boto3官方客户端,旨在提供一个更干净、更pythonic的接口来处理aws资源。
目前,boto3已经提供了the Resource Model,这是一个比原始json as explained here更好、更面向对象的接口。虽然它可以工作,但它没有为我当前需要的资源提供接口。这个项目是根据我个人的需要启动的,目的是缓解目前ecs资源的编程访问状态。
基本原理
假设要列出集群的所有服务的任务定义。使用纯boto3
,您需要编写如下内容:
session=boto3.Session()ecs_client=session.client('ecs')services=ecs_client.list_services(cluster="MyCluster")['serviceArns']forserviceinservices:s=ecs_client.describe_services(cluster="MyCluster",services=[service])print("The task definition is {}".format(s['services'][0]['taskDefinition']))
但是使用oows
,您可以将此代码重写为如下内容:
cluster=Cluster("MyCluster")forserviceincluster.services:print("The task definition is {}".format(service.task_definition))
快速启动
目前,oows只支持少量的ecs组件和操作。
首先,使用pip安装它
pip install boto3 oows
从现在起,您需要提供一个常规的boto3 Session
importboto3fromoowsimportecss=boto3.Session()# Create a new boto3 Session.cluster=ecs.Cluster("MyCluster",s)# Initialize a new cluster objectservice=ecs.Service("server",cluster,s)# Initialize a new service objecttask_definition=service.task_definition# Gets the service's task definitiontask_definition.update_env("new_env","new_value")# Creates a new task definition with updated env