没有项目描述

aws-autodiscovery-templater的Python项目详细描述


AWS自动发现模板程序

aws中的自动发现对于遗留应用程序来说可能很棘手。由于时间 或者复杂性,编写自动发现代码并不总是可能的。 让应用程序在弹性/伸缩性环境中找到彼此。 有时,在配置文件中列出主机的IP/主机 够了,这个剧本就是这么做的。

安装

安装很简单

$ pip install aws-autodiscovery-templater

用法

最简单的方法是使用附带的cli工具(尽管 您可以使用的小python库)。此项目使用jinja2 templating engine,因此您可以找到 关于如何编写模板的详细信息。以下变量是 传递给模板引擎:

{
    "private": {
        "ips": [...],
        "hostnames": [...]
    },
    "public": {
        "ips": [...],
        "hostnames": [...]
    },
    "reservations": {
        ...
    }
}

前两个条目包含public和 私有、IP和主机名。reservations条目包含raw 输出 EC2.Client.describe_instances

由此,我们可以创建一个如下所示的模板

# /path/to/config.yaml
{% if private['ips'] %}
private_ips:{% for ip in private['ips'] %}
  - {{ ip }}{% endfor %}{% endif %}

我们将在下面的示例中使用此模板。

注意:在运行其中任何一个之前,您需要有您的aws 在~/.aws/{config,credentials}或^{tt2}中设置的凭据$ 环境变量。

示例运行

$ aws-autodiscovery-templater \
  --template-path /path/to/config.yaml \ # Path to jina2 formatted template
  --profile my-aws-profile \                 # AWS credentials as defined in ~/.aws/credentials
  --stdout \                                 # Print result to stdout
  --filter-empty                             # Don't include null/missing values (eg. not all machines have public IPs

过滤实例

更重要的是,可以根据实例的标记筛选实例。这个 filter是一个json对象,其结构与 aws ec2 describe-instances, 排除根["Reservations"]键。

$ aws-autodiscovery-templater \
  --template-path /path/to/config.yaml \
  --profile my-aws-profile \
  --stdout \
  --filter-empty
  --filter "Name=tag:Application,Values=[mongodb,mongodb-master]"
 private_ips:
   - 10.0.0.20
   - 10.0.0.10
   - 10.0.0.30

内联帮助:

# For more details, have a look at the --help option
$ aws-autodiscovery-templater --help
usage: aws-autodiscovery-templater [-h]
                                   [--aws-access-key-id AWS_ACCESS_KEY_ID]
                                   [--aws-secret-access-key AWS_SECRET_ACCESS_KEY]
                                   [--aws-session-token AWS_SESSION_TOKEN]
                                   [--region REGION] [--profile PROFILE]
                                   [--role ROLE] [--auth-debug]
                                   [--role-session-name ROLE_SESSION_NAME]
                                   --template-path TEMPLATE_PATH --stdout
                                   [--vpc-ids] [--filter FILTER]
                                   [--filter-empty]

optional arguments:
  -h, --help            show this help message and exit

AWS credentials:
  --aws-access-key-id AWS_ACCESS_KEY_ID
                        AWS access key
  --aws-secret-access-key AWS_SECRET_ACCESS_KEY
                        Access and secret key variables override credentials
                        stored in credential and config files
  --aws-session-token AWS_SESSION_TOKEN
                        A session token is only required if you are using
                        temporary security credentials.
  --region REGION       This variable overrides the default region of the in-
                        use profile, if set.
  --profile PROFILE     This can be the name of a profile stored in a
                        credential or config file, or default to use the
                        default profile.
  --role ROLE           Fully qualified role arn to assume
  --auth-debug          Enter debug mode, which will print credentials and
                        then exist at `create_session`.
  --role-session-name ROLE_SESSION_NAME
                        If you have assigned a role, set a --role-session-name

AWS Autodiscovery Templater:
  --template-path TEMPLATE_PATH
                        Path to the template to fill variables into.
  --stdout              Prints a json object containing the retrieves
                        resources
  --vpc-ids             Optionally restrict the filtering to a particular list
                        of IPs. Comma seperated list of vpc-ids.
  --filter FILTER       Filter for ec2 instances as defined in http://boto3.re
                        adthedocs.org/en/latest/reference/services/ec2.html#EC
                        2.Client.describe_instances
  --filter-empty        By default, missing values are returned as null to
                        keep private/public ip/hostname sets of equal length.
                        This removes null values from the filter

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

推荐PyPI第三方库


热门话题
java如何向类添加适用于该类中所有对象的单个@XmlAttribute注释   java未处理的继续记录跟踪类org。阿帕奇。波伊。hssf。记录塔比德雷科德   Eclipse中java代码的rest连接超时,而不是浏览器的rest连接超时   数组我的Java插入排序逻辑有什么问题?   java使用Http客户端进行请求,该请求返回内容类型为“application/vnd.msexcel”的jsp页面   java连接到数据库(Derby)   url编码如何使用java发布而不使用url编码url的查询部分   正则表达式使用Java替换字符串中的模式   Java中声明数组的区别   java hibernate ReferenceColumnNames未映射到单个属性   java如何对地图集合的分层键进行排序?   java ValueAnimator在我的手机上似乎工作不正常   java如何使用Hibernate Lucene搜索访问实体中外键的排序字段名?   在同一台机器上以不同的JAVA路径运行两个Tomcat   java如何在Eclipse中记录最新的git提交哈希?   java为什么我必须将JRE、编译器和facet全部降级为Java1。8在Eclipse中创建简单Web服务时   无法将java DataBufferInt解析为类型