aws云信息创建库

troposphere的Python项目详细描述


PyPI VersionBuild Statuslicense: New BSD licenseDocumentation Status

关于

对流层-创建AWS CloudFormation描述的库

通过编写描述aws资源的python代码,对流层库允许更容易地创建AWS CloudFormation JSON。对流层也 包括一些通过heat对OpenStack resources的基本支持。

为了便于在早期捕获cloudformation或json错误,库具有 类中内置的属性和类型检查。

安装

对流层可以通过python的pip分发系统安装 发布:

$ pip install troposphere

awacs安装对流层 (推荐的软依赖):

$ pip install troposphere[policy]

或者,可以通过克隆此存储库来运行use setup.py进行安装 并发布:

$ python setup.py install  # you may need sudo depending on your python installation

示例

创建实例的简单示例如下:

>>>fromtroposphereimportRef,Template>>>importtroposphere.ec2asec2>>>t=Template()>>>instance=ec2.Instance("myinstance")>>>instance.ImageId="ami-951945d0">>>instance.InstanceType="t1.micro">>>t.add_resource(instance)<troposphere.ec2.Instanceobjectat0x101bf3390>>>>print(t.to_json()){"Resources":{"myinstance":{"Properties":{"ImageId":"ami-951945d0","InstanceType":"t1.micro"},"Type":"AWS::EC2::Instance"}}}

创建实例(yaml)的简单示例如下:

>>>fromtroposphereimportRef,Template>>>importtroposphere.ec2asec2>>>t=Template()>>>instance=ec2.Instance("myinstance")>>>instance.ImageId="ami-951945d0">>>instance.InstanceType="t1.micro">>>t.add_resource(instance)<troposphere.ec2.Instanceobjectat0x101bf3390>>>>print(t.to_yaml())Resources:myinstance:Properties:ImageId:ami-951945d0InstanceType:t1.microType:AWS::EC2::Instance

或者,可以使用参数代替属性:

>>>instance=ec2.Instance("myinstance",ImageId="ami-951945d0",InstanceType="t1.micro")>>>t.add_resource(instance)<troposphere.ec2.Instanceobjectat0x101bf3550>

并且add_resource()返回该对象,以便与Ref()一起使用:

>>>instance=t.add_resource(ec2.Instance("myinstance",ImageId="ami-951945d0",InstanceType="t1.micro"))>>>Ref(instance)<troposphere.Refobjectat0x101bf3490>

错误检查示例(为了清晰起见,删除了完整的回溯):

在aws资源上设置的属性不正确:

>>>importtroposphere.ec2asec2>>>ec2.Instance("ec2instance",image="i-XXXX")Traceback(mostrecentcalllast):...AttributeError:AWS::EC2::Instanceobjectdoesnotsupportattributeimage

aws资源属性的类型不正确:

>>>ec2.Instance("ec2instance",ImageId=1)Traceback(mostrecentcalllast):...TypeError:ImageIdis<type'int'>,expected<type'basestring'>

缺少aws资源的必需属性:

>>>fromtroposphereimportTemplate>>>importtroposphere.ec2asec2>>>t=Template()>>>t.add_resource(ec2.Instance("ec2instance",InstanceType="m3.medium"))<troposphere.ec2.Instanceobjectat0x109ee2e50>>>>print(t.to_json())Traceback(mostrecentcalllast):...ValueError:ResourceImageIdrequiredintypeAWS::EC2::Instance

当前支持的AWS资源类型

  • aws::amazonq
  • aws::放大
  • aws::apigateway
  • aws::apigatewayv2
  • aws::appmesh
  • aws::appstream
  • aws::appsync
  • aws::应用程序自动缩放
  • 雅典娜
  • 自动缩放
  • 自动缩放计划
  • aws::批次
  • aws::预算
  • aws::证书管理员
  • AWS::云9
  • 云信息
  • aws::云锋
  • aws::cloudtrail
  • aws::cloudwatch
  • aws::代码构建
  • aws::codecommit
  • aws::代码部署
  • aws::代码管道
  • aws::代码星
  • aws::干邑
  • aws::配置
  • aws::dax
  • aws::dlm
  • AWS::DMS
  • aws::数据管道
  • aws::目录服务
  • aws::文档数据库
  • AWS::发电机
  • aws::ec2
  • AWS::电子收银机
  • aws::ecs
  • aws::efs
  • aws::eks
  • AWS::电子病历
  • aws::弹性体
  • 弹性豆茎
  • aws::弹性负载平衡
  • AWS::弹性加载平衡v2
  • aws::弹性搜索
  • aws::事件
  • aws::fsx
  • aws::胶水
  • aws::绿草
  • aws::担保
  • aws::iam
  • AWS::检查员
  • AWS::物联网
  • aws::iot1单击
  • aws::物联网分析
  • aws::物联网事件
  • aws::kms
  • aws::动觉
  • 运动分析
  • 运动分析2
  • aws::动态消防软管
  • aws::lakeformation
  • aws::lambda
  • aws::日志
  • aws::managedblockchain
  • aws::媒体直播
  • aws::媒体商店
  • aws::msk
  • 海王星
  • AWS::Opsworks
  • aws::opsworkscm
  • aws::精确定位邮件
  • aws::ram
  • aws::rds
  • aws::红移
  • aws::罗博马克
  • AWS::路径53
  • AWS::路由53解析器
  • aws::s3
  • AWS::SDB
  • AWS::SES
  • aws::sns
  • aws::sqs
  • AWS::SSM
  • aws::sagemaker
  • aws::secretsmanager
  • aws::安全中心
  • aws::无服务器
  • aws::服务目录
  • aws::服务发现
  • aws::步骤函数
  • aws::传输
  • aws::waf
  • aws::waf地区
  • aws::工作区

当前支持的OpenStack资源类型

  • 操作系统::中子::防火墙
  • 操作系统::中子::防火墙策略
  • <升i>操作系统::中子::防火墙规则
  • 操作系统::中子::浮动IP
  • 操作系统::中子::浮动关联
  • 操作系统::中子::健康监测器
  • 操作系统::中子::池
  • 操作系统::中子::负载均衡器
  • 操作系统::中子::净
  • os::中子::池成员
  • 操作系统::中子::端口
  • 操作系统::中子::安全组
  • 操作系统::nova::浮动IP
  • os::nova::浮动关联
  • os::nova::密钥对
  • 操作系统::nova::服务器

待办事项:

  • 添加其他有效性检查

复制单个实例示例如下所示

# Converted from EC2InstanceSample.template located at:# http://aws.amazon.com/cloudformation/aws-cloudformation-templates/fromtroposphereimportBase64,FindInMap,GetAttfromtroposphereimportParameter,Output,Ref,Templateimporttroposphere.ec2asec2template=Template()keyname_param=template.add_parameter(Parameter("KeyName",Description="Name of an existing EC2 KeyPair to enable SSH ""access to the instance",Type="String",))template.add_mapping('RegionMap',{"us-east-1":{"AMI":"ami-7f418316"},"us-west-1":{"AMI":"ami-951945d0"},"us-west-2":{"AMI":"ami-16fd7026"},"eu-west-1":{"AMI":"ami-24506250"},"sa-east-1":{"AMI":"ami-3e3be423"},"ap-southeast-1":{"AMI":"ami-74dda626"},"ap-northeast-1":{"AMI":"ami-dcfa4edd"}})ec2_instance=template.add_resource(ec2.Instance("Ec2Instance",ImageId=FindInMap("RegionMap",Ref("AWS::Region"),"AMI"),InstanceType="t1.micro",KeyName=Ref(keyname_param),SecurityGroups=["default"],UserData=Base64("80")))template.add_output([Output("InstanceId",Description="InstanceId of the newly created EC2 instance",Value=Ref(ec2_instance),),Output("AZ",Description="Availability Zone of the newly created EC2 instance",Value=GetAtt(ec2_instance,"AvailabilityZone"),),Output("PublicIP",Description="Public IP address of the newly created EC2 instance",Value=GetAtt(ec2_instance,"PublicIp"),),Output("PrivateIP",Description="Private IP address of the newly created EC2 instance",Value=GetAtt(ec2_instance,"PrivateIp"),),Output("PublicDNS",Description="Public DNSName of the newly created EC2 instance",Value=GetAtt(ec2_instance,"PublicDnsName"),),Output("PrivateDNS",Description="Private DNSName of the newly created EC2 instance",Value=GetAtt(ec2_instance,"PrivateDnsName"),),])print(template.to_json())

社区

我们有一个google群组cloudtools-dev,你可以在这里提问 与对流层社区接触。问题和请求总是 欢迎!

许可

对流层是根据BSD 2-Clause license授权的。 对流层许可证全文见LICENSE

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
添加组件后,java JTable为空   java将json发送到php并插入mysql,但返回null   java Spring引导JNDI CommonJ资源   从不同PC创建和合并后的Java servlet问题   java如何在使用findelements时从xpath获取文本   java使用spring boot使用gmail smtp发送电子邮件   java在不使用pojo、bean或getter和setter的情况下获取Json标题的Json数组   Java中的OpenFile对话框将null作为响应   JavaBuilder模式。扩展接口   java中无需替换的数据结构选取   java如何评价Encog中的预测神经网络   java如何在安卓中使用实际的HttpURLConnection进行单元测试?   java使用XML配置禁用WebSocket中的CSRF保护   java如何通过hibernate从多表查询中获取数据?   mysql如何在java中获取更新的行Id   java AEM/CQ组件单一组件/有限组件   java FFmpeg Javacv延迟问题   显示整数数组的java不起作用