我经常使用一些有用的aws脚本

aws-scripts的Python项目详细描述


PyPIlicense

AWS脚本

在这里您将发现一些有用的aws脚本,我不时使用。

所有脚本都依赖于Boto,这是一个python包,它为amazon web服务提供接口。

因此,要使用这些脚本,您需要安装boto并提供aws证书:

要安装aws脚本和所有必需的python包,只需键入:

pip install aws-scripts 

如果依赖项已经满足,则不会安装任何内容。

要提供您的aws凭据,请使用boto/boto3配置文件~/.aws/credentials

[default]aws_access_key_id=<XXXXXXXXXXXXXXXXXXX>aws_secret_access_key=<xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>region=xx-xxxx-x

Note that you can use the environment variable: AWS_DEFAULT_REGION=xx-xxxx-x to override the default region on the config file. In the ec2-instances.py script you can also use the --region option for the same purpose

ec2实例.py

列出EC2实例,包括名称标签、IP、类型、区域、VPC、ID和状态。

可以按名称、类型和/或状态筛选结果。或者您可以提供实例ID的列表。

最后,您可以对过滤器或列表返回的所有实例执行远程命令。

'-h'选项显示如何使用可用选项。

usage: ec2-instances.py [-h] [-n NAME] [-t TYPE] [-s STATUS]
                        [-l ID_LIST [ID_LIST ...]] [-e EXECUTE] [-r REGION]
                        [-u USER]

optional arguments:
  -h, --help            show this help message and exit
  -n NAME, --name NAME  Filter result by name.
  -t TYPE, --type TYPE  Filer result by type.
  -s STATUS, --status STATUS
                        Filter result by status.
  -l ID_LIST [ID_LIST ...], --id_list ID_LIST [ID_LIST ...]
                        Provide a list of InstanceIds.
  -e EXECUTE, --execute EXECUTE
                        Execute a command on instances
  -r REGION, --region REGION
                        Specify an alternate region to override the one
                        defined in the .aws/credentials file
  -u USER, --user USER  User to run commands if -e option is used. Ubuntu user
                        is used by default

ec2保留.py

列出所有实例预订的详细信息,包括按类型和大小列出的活动预订的摘要。

摘要还显示了应用规范化因子后保留的活动容量。这有助于将保留容量与部署在生产中的容量进行比较。

您还可以使用选项--create-google-calendar-events在您的google日历帐户中添加活动预订的到期日期。

usage: ec2-reserved.py [-h]
                        [-s {payment-pending,active,payment-failed,retired}]
                        [--create-google-calendar-events] [-t TYPE]

Show reserved EC2 instances

optional arguments:
  -h, --help            show this help message and exit
  -s {payment-pending,active,payment-failed,retired}, --state {payment-pending,active,payment-failed,retired}
                        Filer result by reservation state.
  --create-google-calendar-events
                        Create events in your Google Calendar, using the
                        expiration dates of your active reservations
  -t TYPE, --type TYPE  Filer result by instance type.

要使用google日历功能,只需enable the calendar API in your Google Account并在Google Calendar中创建一个名为aws的日历。然后创建oauth client id凭据。下载凭据文件并将其另存为aws脚本文件夹repo中的client_secret.json。首次使用--create-google-calendar-events选项运行脚本时,将打开一个Web浏览器,要求您使用要使用的Google帐户登录。

然后,每当您在amazon web服务上购买新预订时,只要运行脚本,就可以在日历中添加新预订。

EC2极压比

列出所有弹性负载平衡器及其相关实例。

usage: ec2-elb.py [-h]

For every Elastic Load Balancer list the attached instances

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

EC2快照管理py

使用此脚本,您可以看到快照与ebs卷和ami之间的关系。这允许您选择不需要保存在aws s3服务中的快照。

默认情况下,脚本显示与每个快照相关的所有卷和ami。

您还可以显示与每个卷相关的所有快照。当您只想为每个卷保留一定数量的快照时,此选项特别有用。

最后,您可以显示与每个ami相关的所有快照。

'-h'选项显示如何使用可用选项。

usage: ec2-snap-mgmt.py [-h] [-v {orphan,volumes}] owner_id

positional arguments:
  owner_id              12-digit AWS Account Number

optional arguments:
  -h, --help            show this help message and exit
  -v {orphan,volumes,images}, --view {orphan,volumes,images}
                        Available views: orphan and volumes. Orphan is the
                        default one.

该脚本实际上没有删除任何内容,只是在树状图中显示关系。

s3 mongodump.py

这是一个在amazon s3上进行mongodb备份的工具。

它使用mongodump执行本地或远程mongodb实例的二进制备份。转储的文件被压缩到tarball文件中并上传到amazon s3存储桶中。 您可以指定要保留在存储桶中的副本数。最老的将被自动删除。

usage: s3-mongodump.py [-h] [-u USER] [-p PASSWORD] [-H HOST] [-d DATABASE]
                       [-o OUT] [-n NUMBER] -b BUCKET [-P PREFIX]

A tool to make mongodb backups on Amazon s3

optional arguments:
  -h, --help            show this help message and exit
  -u USER, --user USER  Mongodb user (optional)
  -p PASSWORD, --password PASSWORD
                        Mongodb password (optional)
  -H HOST, --host HOST  Mongodb host: <hostname>:<port>.
  -d DATABASE, --database DATABASE
                        The database to backup (all if not provided)
  -o OUT, --out OUT     The output directory for dumped files
  -n NUMBER, --number NUMBER
                        Number of copies to retain in the S3 bucket
  -b BUCKET, --bucket BUCKET
                        Amazon s3 bucket.
  -P PREFIX, --prefix PREFIX
                        For grouped objects aka s3 folders, provide the prefix
                        key

route53设置hostname.py

此脚本允许您为使用aws自动缩放启动的实例自动设置可预测的dns记录。

它打算在启动时从ec2实例执行。 脚本在DNS区域中查找与提供的模式匹配的可用名称。然后,它将此名称作为CNAME记录添加到指向EC2实例公共名称的DNS区域中。

usage: route53-set-hostname.py [-h] --HostedZoneId HOSTEDZONEID --HostStr
                               HOSTSTR [--rangeSize RANGESIZE] [--dryrun]

AWS Route53 hostname managment for Autoscaled EC2 Instances

optional arguments:
  -h, --help            show this help message and exit
  --HostedZoneId HOSTEDZONEID
                        The ID of the hosted zone where the new resource
                        record will be added.
  --HostStr HOSTSTR     The host string used to build the new name
  --rangeSize RANGESIZE
                        The maximun number to be assigned. The first available
                        will be used
  --dryrun              Shows what is going to be done but doesn't change
                        anything actually

示例:

user@host:~$ ./route53-set-hostname.py --HostedZoneId XXXXXXXXXXXXXX --HostStr websrv --rangeSize 1015:41:58 06/09/16: creating CNAME websrv03.example.com. -> ec2-XX-XX-XXX-XX.compute-1.amazonaws.com......INSYNC

路径53 del hostname.py

此脚本在关机时从ec2实例执行。 脚本从传递的dns区域标识符中删除其主机记录区域。

usage: route53-del-hostname.py [-h] --HostedZoneId HOSTEDZONEID [--dryrun]

AWS Route53 hostname managment for Autoscaled EC2 Instances

optional arguments:
  -h, --help            show this help message and exit
  --HostedZoneId HOSTEDZONEID
                        The ID of the hosted zone where the new resource
                        record will be added.
  --dryrun              Shows what is going to be done but doesn't change
                        anything actually

s3下载文件.py

这个脚本只是下载requested s3对象。

usage: s3-download-file.py [-h] -b BUCKET -o OBJECTKEY -f FILEPATH

Donwload file from AWS S3

optional arguments:
  -h, --help            show this help message and exit
  -b BUCKET, --bucket BUCKET
                        The bucket name.
  -o OBJECTKEY, --objectkey OBJECTKEY
                        The host string used to build the new name
  -f FILEPATH, --filepath FILEPATH
                        The filepath of the file to be saved

生命周期挂钩worker.py

正如它自己的名字所说,这个worker被设计成使用自动缩放lifecycle hooks

该进程查找与自动缩放组关联的sqs队列中的传入消息。然后,当一条消息到达实例时,它将被消费并触发相关的自定义操作。最后,使用lifecyle操作令牌,工作进程完成启动或结束实例操作时进行的自动缩放操作。

usage: lifecycle-hook-worker.py [-h] -q QUEUE -s {LAUNCHING,TERMINATING} -g
                                GROUP -H HOOKNAME -e EXECUTE [-w WAIT]

SQS Lifecycle hook consumer and trigger

optional arguments:
  -h, --help            show this help message and exit
  -q QUEUE, --queue QUEUE
                        Queue resource.
  -s {LAUNCHING,TERMINATING}, --state {LAUNCHING,TERMINATING}
                        Indicates if the consumer is waiting for LAUNCHING or
                        TERMINATING state
  -g GROUP, --group GROUP
                        Auto Scaling Group Name
  -H HOOKNAME, --hookName HOOKNAME
                        Life Cycle Hook Name
  -e EXECUTE, --execute EXECUTE
                        The filepath of the triggered script
  -w WAIT, --wait WAIT  Time between query loops in seconds (default: 60)

rds instances.py

显示有关所有rds实例的主要信息,例如:端点、引擎、版本、状态等。

usage: rds-instances.py [-h]

List all the RDS instances

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

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

推荐PyPI第三方库


热门话题
java GridBagLayout集合JScrollPane相对于JButton高度   使用JAXWS的java:如何设置用户代理属性   java使用Jackson将巨大的JSON响应反序列化为POJO最有效的方法是什么?   java如何实现对bouncy ball的声明?   java使用Hibernate显示给定parentNode的所有子节点   javascript模式引导与应用程序Spring引导(JAVA)   机器学习在weka java中有没有计算P值的方法?   mymysql中的java数据不一致   几何学在Java中,对于任何具有起始坐标和结束坐标的直线,如何获得矩形的4个角   java我需要读取一个字符串并从中获取一个特定的值   java短长度身份验证令牌   读取Android NFC IsoDep标记时发生java连接错误   java NoSuchMethodError:将Firebase与应用程序引擎应用程序集成时出错   java如何编写超级工厂程序?   java关联与聚合   java问题集作为学习编程未来、承诺和参与者的资源