用对流层管理aws云层的一个类似地形的实用程序

tropoform的Python项目详细描述


对流层形态

tropoform是一个为aws提供类似于terraform的接口的工具。 由对流层创建的云形成堆栈

可以创建至少有一个方法的对流层脚本(python模块):get_template() 并使用对流层来计划、应用、破坏云层堆栈。

要求

  • python3-很抱歉,不打算将它移植回python 2.x
  • Tropoform-可与PIP一起安装PIP3安装Tropoform

tropoform安装以下附加库,这些库可能有助于开发 对流层脚本

  • 对流层-创建云形成模板。(与对流层一起安装)
  • awacs-aws策略创建库
  • boto3-python aws sdk

安装

安装最新版本的tropoform

pip install tropoform --user --upgrade

对于开发项目,建议安装在python中 虚拟环境

或者,您可以从源代码安装https://github.com/cloudshiftstrategies/tropoform" rel="nofollow">https://github.com/cloudshiftstrategies/tropoform

用法

使用tropoform-h获得帮助

$ tropform -h
usage: tropoform [-h] [-v]
                    {apply,plan,destroy,list,output,parameters,reason} ...

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         get DEBUG logging

operation:
  {apply,plan,destroy,list,output,parameters,reason}
    apply               create or update stack
    plan                view change plan
    destroy             remove stack
    list                list stacks
    output              view stack outputs
    parameters          list parameters used in a stack
    reason              list reasons for failed stack

有关操作的详细使用帮助,请参见tropoform apply-h

usage: tropoform apply [-h] [-m MODULE_NAME] [-p PARAMETER_FILES]
                          [-c CAPABILITIES] [-r REGION] [--auto_approve]
                          stack_name

positional arguments:
  stack_name            The name of the cloud formation stack on which to
                        perform operation. If a module exists in the current
                        working directory that matches the stack_name and has
                        a get_template() method, module_name is not required

optional arguments:
  -h, --help            show this help message and exit
  -m MODULE_NAME, --module_name MODULE_NAME
                        The name of the python troposphere module that will
                        create the template. Module must have a get_template()
                        method that returns a valid troposphere.Template
                        object
  -p PARAMETER_FILES, --parameter_files PARAMETER_FILES
                        Comma separated yaml parameter files that will be
                        passed to cloud formation as parameters
  -c CAPABILITIES, --capabilities CAPABILITIES
                        Comma separated list of AWS capabilities. default:
                        CAPABILITY_NAMED_IAM
  -r REGION, --region REGION
                        The name of the AWS region to perform operations.
                        default is the env variable: AWS_DEFAULT_REGION
  --auto_approve        If set, user will not be prompted to approve changes.
                        default=False

用法示例

  1. 使用至少有一个名为get_template()的函数的tropoform创建一个python脚本 返回未渲染的对流层.template()对象。

    在下面的example.py脚本中,我们在函数get_template()中创建一个iam用户并返回 已完成的模板对象

    示例.py

    fromtroposphereimportTemplatefromtroposphereimportiamdefget_template():template=Template()template.add_resource(iam.User("testIamUser",UserName="tropoform_test_user"))returntemplate
  2. 配置您的aws凭据 https://docs.aws.amazon.com/sdk for java/v1/developer-guide/setup credentials.html 以便您可以进行api/cli调用。

    • 使用awscli命令测试您的凭据,如aws s3 ls
    • 或者您可以测试boto3 python apipython3-c"import boto3;client=boto3.client('s3');print(client.list_buckets())"
  3. 在堆栈上运行tropoform计划,并查看是否将创建一个iam用户资源

    $ tropoform plan myStack -m example.py
    STACK: myStack is not yet deployed
    STACK: myStack creates 1
    # ) action   logical_id                resource_type
     1) Create   testIamUser               AWS::IAM::User
    
  4. 使用(创建)堆栈

    $ tropoform apply myStack -m example.py
    STACK: myStack, Current Status: None
    CREATING Stack: myStack with 1 resources
    Are you sure? [yes|no] yes
    STACK: myStack, Status: CREATE_IN_PROGRESS - 16:36:10
    STACK: myStack, Status: CREATE_IN_PROGRESS - 16:36:25
    STACK: myStack, Status: CREATE_COMPLETE - 16:36:41
    STACK: myStack deployed 1 resources in 00:00:48
    STACK OUTPUTS:
    
  5. 使用tropoform list查看应用的堆栈。请注意,它处于"创建完成"状态

    $ tropoform list
    stack_name           stack_status         drift_status         stack_description
    myStack              CREATE_COMPLETE      NOT_CHECKED  
    
  6. 更新example.template并添加另一个资源

    示例.py

    fromtroposphereimportTemplatefromtroposphereimportiamdefget_template():template=Template()template.add_resource(iam.User("testIamUser",UserName="tropoform_test_user"))template.add_resource(iam.User("testIamUser2",UserName="tropoform_test_user2"))returntemplate

    运行一个新的对流层计划。请注意,它将添加一个新资源。

    $ tropoform plan myStack -m example.py
    STACK: myStack has 1 detected changes
    # ) action   logical_id           resource_id               resource_type                  scope      Replace?
     1) Add      testIamUser2                                   AWS::IAM::User                 [] 
    
  7. tropoform应用更改,然后使用tropoform列表进行验证

    pip install tropoform --user --upgrade
    
    0
  8. 完成后销毁堆栈

    pip install tropoform --user --upgrade
    
    1
  9. < > >

    附加功能

    1. 参数文件

      通常,cloudformation模板将需要参数,以便它们可以很容易地 可重复使用的。可以使用key:value对创建基于yaml的文件,并将其添加为 对流层计划和对流层应用操作的参数

      示例_parms1.yaml

      pip install tropoform --user --upgrade
      
      2

      示例_parms2.yaml

      pip install tropoform --user --upgrade
      
      3

      在应用程序中使用参数文件

      pip install tropoform --user --upgrade
      
      4
    2. 能力

      云形成堆栈可能需要确认它将创建 某些类型。最常见的是授权云形成的功能 创建IAM资源。这个默认情况下包含在对流层中。但是如果你的堆栈 需要其他功能,可以将它们与-c参数一起包含。查看更多 本文档中有关功能的信息: https://docs.aws.amazon.com/awscloudformation/latest/apirerence/api廑createstack.html

      在应用程序中使用附加功能

      pip install tropoform --user --upgrade
      
      5
    3. 区域

      默认情况下,对流层将读取环境变量aws_default_region以确定 在哪里管理堆栈。但是如果你想为一个操作指定一个不同的区域 传递'-r'或'--region'参数

      在列表命令中指定区域

      pip install tropoform --user --upgrade
      
      6
    4. 堆栈名称和模块名称

      如果要为cloudformation堆栈指定的名称是 工作目录和与对流层脚本同名,则可以省略 module_name参数

      当对流层为"example.py"时,创建一个称为"example"的云形成堆栈的示例 当前工作目录中存在脚本

      pip install tropoform --user --upgrade
      
      7

      当对流层为"example.py"时创建一个称为"mystack"的云形成堆栈的示例 脚本存在于某些文件系统位置

      pip install tropoform --user --upgrade
      
      8
    5. 自动批准

      有时在自动脚本中运行tropoform时,您不想被提示说 是以确认应用销毁操作

      示例--auto_approve

      pip install tropoform --user --upgrade
      
      9
    6. 失败原因

      如果您的cloudformation堆栈由于某种原因未能应用,则cloudformation事件 这导致将被打印。

      在下面的示例中,我们试图附加一个故意拼写错误的managediampolicy

      $ tropform -h
      usage: tropoform [-h] [-v]
                          {apply,plan,destroy,list,output,parameters,reason} ...
      
      optional arguments:
        -h, --help            show this help message and exit
        -v, --verbose         get DEBUG logging
      
      operation:
        {apply,plan,destroy,list,output,parameters,reason}
          apply               create or update stack
          plan                view change plan
          destroy             remove stack
          list                list stacks
          output              view stack outputs
          parameters          list parameters used in a stack
          reason              list reasons for failed stack
      
      0

      您可以使用对流层形式原因操作查找失败堆栈的状态

      $ tropform -h
      usage: tropoform [-h] [-v]
                          {apply,plan,destroy,list,output,parameters,reason} ...
      
      optional arguments:
        -h, --help            show this help message and exit
        -v, --verbose         get DEBUG logging
      
      operation:
        {apply,plan,destroy,list,output,parameters,reason}
          apply               create or update stack
          plan                view change plan
          destroy             remove stack
          list                list stacks
          output              view stack outputs
          parameters          list parameters used in a stack
          reason              list reasons for failed stack
      
      1
    7. 参数

      如果使用参数部署堆栈,则可以使用 对流层形状参数操作

      $ tropform -h
      usage: tropoform [-h] [-v]
                          {apply,plan,destroy,list,output,parameters,reason} ...
      
      optional arguments:
        -h, --help            show this help message and exit
        -v, --verbose         get DEBUG logging
      
      operation:
        {apply,plan,destroy,list,output,parameters,reason}
          apply               create or update stack
          plan                view change plan
          destroy             remove stack
          list                list stacks
          output              view stack outputs
          parameters          list parameters used in a stack
          reason              list reasons for failed stack
      
      2
    8. 输出

      如果堆栈指定了输出参数,则在完成部署堆栈时,将输出 将被打印。

      $ tropform -h
      usage: tropoform [-h] [-v]
                          {apply,plan,destroy,list,output,parameters,reason} ...
      
      optional arguments:
        -h, --help            show this help message and exit
        -v, --verbose         get DEBUG logging
      
      operation:
        {apply,plan,destroy,list,output,parameters,reason}
          apply               create or update stack
          plan                view change plan
          destroy             remove stack
          list                list stacks
          output              view stack outputs
          parameters          list parameters used in a stack
          reason              list reasons for failed stack
      
      3

      如果以后要访问这些输出,可以运行tropoform output

      $ tropform -h
      usage: tropoform [-h] [-v]
                          {apply,plan,destroy,list,output,parameters,reason} ...
      
      optional arguments:
        -h, --help            show this help message and exit
        -v, --verbose         get DEBUG logging
      
      operation:
        {apply,plan,destroy,list,output,parameters,reason}
          apply               create or update stack
          plan                view change plan
          destroy             remove stack
          list                list stacks
          output              view stack outputs
          parameters          list parameters used in a stack
          reason              list reasons for failed stack
      
      4
    9. < > >

      欢迎投稿!

      打开问题并通过github repo发送pull请求https://github.com/cloudshiftstrategies/tropoform

      构建说明

      $ tropform -h
      usage: tropoform [-h] [-v]
                          {apply,plan,destroy,list,output,parameters,reason} ...
      
      optional arguments:
        -h, --help            show this help message and exit
        -v, --verbose         get DEBUG logging
      
      operation:
        {apply,plan,destroy,list,output,parameters,reason}
          apply               create or update stack
          plan                view change plan
          destroy             remove stack
          list                list stacks
          output              view stack outputs
          parameters          list parameters used in a stack
          reason              list reasons for failed stack
      
      5

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

      推荐PyPI第三方库


热门话题
java为什么运行这么长时间?   具有多行插入的java Quarkus Hibernate/Panache NativeQuery   强力创建类并将其添加到数组中会导致奇怪的结果   java将KeyListener添加到Jframe问题   java简单Spring EL表达式不起作用;带有错误类型失配异常   java中求偶数整除数的有效方法   java静态方法和实例方法的内存表示之间的差异   Java 8 LocalDateTime到日期丢失时区   如何在Java中以编程方式创建XML文档?   Hyperledger结构智能合约中的java如何打开日志记录?   java关键帧动画   单击TableRowSorter时,java获取所选行中的用户对象   java Android应用程序挂起   JAVAlang.AbstractMethodError:org。jboss。资源适配器。jdbc。jdk5。WrappedConnectionJDK5。createBlob()Ljava/sql/Blob;   调用java类表单velocity模板(.vt)文件   java Struts |类型转换错误