my_aws_api_library.MyAws(aws_cr_fl, pb_ky_fl)[source]¶Bases: object
create_ec2_instance(customer_id, node_type)[source]¶Crete the Ec2 instance, and save the customer-id tag value.
Each instance will have Amazon SSMAgent at launch. Tested only with Amazon Linux Instances (Free Tier).
Each instance have “AmazonEC2RoleforSSM” to build a SSM connection for remote command run.
If node_type “Peer”, Instance is t2.micro and has 10gb EBS disk.
If node_type “Manager”, Instance is t2.medium and has 20gb EBS disk.
customer_id: The customer id tag value of instance that will be created.
node_type : The node type of instance that will be created. (“Peer” or “Manager”)
execute_commands_on_linux_instances(commands, instance_ids)[source]¶Execute the specified commands on specified Instances using SSM service.
commands: Command phrases that will be executed
instance_ids: Instances that will run the commands
See also
Amazon EC2 Systems Manager (SSM) requires;
1. An IAM role for EC2 instances that will process commands. There should be a system manager role and the instance should use this role ! (It is done while creation instance)
2. And a separate role for users executing commands. Aws IAM user that has access and secret keys should have ssm permission. (i.e. AmazonSSMFullAccess)
http://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-configuring-access-policies.html
get_all_instances()[source]¶List the all Instances according to their sorted Customer ID
get_customer_by_instance_id(ins_id)[source]¶When given an instance ID, return the Customer IDs from the Instance’s customer-id tag.
Warning
Assumes that an instance should be owned by only one customer.
get_instance_by_customer_id(cid)[source]¶When given a Customer ID, return the Instances’s IDs using the Instance’s customer-id tag.
get_instance_by_node_type(ntype)[source]¶When given an Node Type, return the instance IDs using the Instance’s node-type tag.
list_backups(node_id)[source]¶Return all the backups belongs to specified Instance, with their start-time.
make_backup(n_id)[source]¶Backup the specified Instance’s “/data” mount point.
For clearness, first, script creates a volume for Instance, format it and mount it to /data mount point.
Note
Don’t forget to provide an IAM role (policy –> AmazonEC2RoleforSSM) for the Instance and permission (AmazonSSMFullAccess) for the user. This script uses SSM send_command !
roll_back(back_id, n_id)[source]¶Search for the volumes associate with the given snapshot, detach and delete these volumes. Create new volumes from specified snapshot then attach them to the instance. While doing this steps, take into account the mount points.
back_id: Snapshot ID that will restore
n_id: Instance ID