CENTOS6-AWS Automated operation-Dimension script sharing

Source: Internet
Author: User
Tags awscli

Background information:

The current project uses a large number of AWS EC2 instances as servers, and in automating operational dimensions, we have been using the AWS CLI command-line tool and then invoking it in a shell script.
I recently wanted to create a instance by scripting a "Clone" feature that simulates the "Launch more like" on the Web console. But it's not comfortable to implement in a shell script, so just use Python's Boto library to write one and share it here.

Specific content:

Script Address: https://github.com/mcsrainbow/python-demos/blob/master/demos/awscli.py

Related examples:

Warm tip: My blog page by default does not adopt widescreen mode, if you think the following code is not very beautiful, you can click on the upper right corner of the "<>" switch to widescreen mode.

The code is as follows Copy Code

$./awscli.py-h

usage:awscli.py [-h] (--create |--clone |--terminate)--region Region
[--instance_name instance_name] [--image_id image_id]
[--instance_type Instance_type] [--key_name Key_name]
[--security_group_ids Security_group_ids]
[--subnet_id subnet_id]
[--src_instance_name Src_instance_name]
[--dest_instance_name Dest_instance_name]
[--private_ip_address private_ip_address]
[--instance_id instance_id] [--volume_size Volume_size]
[--volume_type {STANDARD,IO1,GP2}]
[--volume_zone Volume_zone] [--volume_iops Volume_iops]
[--volume_delete_on_termination]
[--load_balancer_name Load_balancer_name]
[--quick]

Examples:
./awscli.py--create--region us-west-1--instance_name idc1-server2
--image_id ami-30f01234--instance_type T1.micro
--key_name Idc1-keypair1--security_group_ids sg-eaf01234f
--subnet_id subnet-6d901234
./awscli.py--create--region us-west-1--instance_name Idc1-server3
--image_id ami-30f01234--instance_type T1.micro
--key_name Idc1-keypair1--security_group_ids sg-eaf01234f
--subnet_id subnet-6d901234--volume_size--volume_type GP2
--volume_zone us-west-1a--volume_delete_on_termination
--load_balancer_name IDC1-ELB1--private_ip_address 172.16.2.23
./awscli.py--clone--region us-west-1--src_instance_name idc1-server1
--dest_instance_name Idc1-server2
./awscli.py--clone--region us-west-1--src_instance_name idc1-server1
--dest_instance_name Idc1-server3--private_ip_address 172.16.2.23
./awscli.py--terminate--region us-west-1--instance_name Idc1-server3
./awscli.py--terminate--region us-west-1--instance_id i-01234abc
./awscli.py--terminate--region us-west-1--instance_id i-01234abc--quick
...

Optional arguments:
-H,--help show this Help and exit
--create Create Instance
--clone Clone Instance
--terminate Terminate Instance
--region Region
--instance_name instance_name
--image_id image_id
--instance_type Instance_type
--key_name Key_name
--security_group_ids Security_group_ids
--subnet_id subnet_id
--src_instance_name Src_instance_name
--dest_instance_name Dest_instance_name
--private_ip_address private_ip_address
--instance_id instance_id
--volume_size volume_size
In GiB
--volume_type {STANDARD,IO1,GP2}
--volume_zone Volume_zone
--volume_iops Volume_iops
--volume_delete_on_termination
Delete volumes on termination
--load_balancer_name Load_balancer_name
--quick no wait on termination
$./awscli.py--create--region us-west-1--instance_name idc1-server1--image_id ami-30f01234
--instance_type t1.micro--key_name idc1-keypair1--security_group_ids sg-eaf01234f
--subnet_id subnet-6d901234--volume_size--volume_type GP2--volume_zone us-west-1a
--volume_delete_on_termination--load_balancer_name idc1-elb1--private_ip_address 172.16.2.21

1. Launching Instance:idc1-server1
2. Creating tag as instance Name: {"name": Idc1-server1}
Instance state:pending
Instance state:running
3. Creating secondary volume for Instance:idc1-server1 as GP2 10G
Volume status:available
4. Attaching volume:vol-4ba6a54c to Instance:idc1-server1 as device:/DEV/SDF
5. Adding Instance:idc1-server1 to ELB:IDC1-ELB1
$./awscli.py--clone--region us-west-1--src_instance_name idc1-server1--dest_instance_name idc1-server2

1. Launching Instance:idc1-server2
2. Creating tag as instance Name: {"name": Idc1-server2}
Instance state:pending
Instance state:running
3. Creating secondary volume for Instance:idc1-server2 as GP2 10G
Volume status:available
4. Attaching volume:vol-5b61635c to Instance:idc1-server2 as device:/DEV/SDF
5. Adding Instance:idc1-server2 to ELB:IDC1-ELB1
$./awscli.py--terminate--region us-west-1--instance_name idc1-server2

Terminating Instance:idc1-server2 id:i-86976d62
Instance State:shutting-down
Instance State:shutting-down
Instance state:terminated

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.