You will write python programs that allows you to automate and manage your AWS cloud services. This assignment will test your ability to use the Boto3 package and Ansible to interact with AWS cloud services, as well as your general Python scripting skills. Use free tier on AWS in all cases, it should not be required to use any paid services.
1. You will write a python program for interacting with AWS services using the Boto3 package. The program will initially prompt the user for a username and password to login to the system, or to select to register a new user. Valid usernames and passwords are to be stored in a file called âpasswords.txtâ, each line of which will contain a username+password pair, and their AWS access key id and secret access key, all separated by tabs, as well as anything else you may want to store.
e.g. the content of a sample âpasswords.txtâ may be:
Â
If the user provides an incorrect username and/or password, issue an appropriate error message and loop, prompting for login credentials again. If the user provides an empty/blank username, exit the program.
Â
If the user selects to register a new account, you should enable allow them to select between a âregularâ account or an âadminâ account, and prompt for them to enter the username and password for the account. Users on âregularâ accounts should not be permitted to perform any commands marked as âadmin onlyâ below. âAdminâ users are able to perform all actions of a âregularâ user as well as all of the âadmin onlyâ functionality too (i.e. they can do everything). Note: This does not mean some special kind of AWS account details are necessary, merely that the python script presents a different set of interface options to the logged in user while running.
Â
Include your âpasswords.txtâ file with your submission, including valid âregularâ and âadminâ credentials for your AWS free account.
Â
2. After providing valid login credentials, the program will use the AWS access key id and secret key associated with that login to form the connection to AWS. Then, the program will present the user with a Python command-line text-based menu for managing AWS. This will direct the user to subsequent submenus outlined below, based upon whether they are a âregularâ or âadminâ level user. A back option should be provided to allow the user to easily navigate the menus and to choose another service after an initial choice. There should also be an option to exit the menus and end the program. Ease of use should be taken into account when designing the menu system.
Display 2 performance metrics (of your choice) gathered for a particular EC2 instance (Prompt the user for the EC2 instance in question), averaged over the last 10minutes.
Â
Set an alarm such that if the CPU utilization is greater than 60% an alarm will be raised. When this alarm is raised, it should stop the instance with over 60% utilization.
Â
Choose from one of the following free tier Amazon services. Describe what it does (in a comment in the python script) and provide a detailed example of how you can manipulate it using boto3 (i.e. implement 4 short example functions which provide different functionality).Autoscaling
3. You should use a boto3 âWaiterâ in at least 1 of the operations which does not complete immediately (e.g. starting an instance, creating a volume from snapshot, etc. ), and provide output telling the user to wait until the operation completes, then permit the user to resume navigating the menu after it completes.
Â
4. Provide a pdf ReadMe document which serves as a user manual, including any necessary requirements/details for running the script (e.g. what subdirectory to place âpasswords.txtâ file in, if not in the main directory) and specifying which file to run to open the main menu. It should also include screenshots demonstrating all working functionality, and indicate any sections which are incomplete or non-functional.
Importantly, please note that you should use best practice when writing your code i.e. use classes/methods where sensible, minimise hardcoding paths, and minimising code duplication. Code should be robust and include error checking so it can deal accordingly with error messages (e.g. if an operation requires that an instance be shut down first, it should not cause the program to crash if we try to run the operation on an active instance). Marks will be awarded for well written robust code.
Â
Your code must include clear concise comments, for functions and also for any complex parts of code which explain what they are doing. These should clearly demonstrate your understanding of the submitted code, i.e. that you understand what type of objects youâre working with, why youâre calling a method with certain arguments etc... Marks will be awarded for this.
Your task is to write a python program which performs the following tasks:
Â
1. Prompt the user to input a value between 1-5 inclusive twice, and then invoke a playbook that will launch 2 groups of the specified numbers of AWS EC2 t2.micro (Free-Tier) instances simultaneously (e.g. if the user enters 2 and 5, you will launch a group of 2 EC2 instances and another group of 5 instances). You must write/generate the playbook yourself. Some examples of launching instances in Ansible have been given at https://docs.ansible.com/ansible/latest/scenario_guides/guide_aws.html.
Â
Hint: python 2.x & boto will need to be installed on the control machine. To simplify compatibility issues with Ansible, it is recommended to install boto and not boto3 on the control machine.
Â
Hint: The key parameter for the ec2 module is looking for the key pair name that has been already uploaded to AWS, not a local key i.e. id_rsa.
Â
2. Invoke a second playbook (again, written by you) which will prompt the user to pick one of the two groups from the previous step, and then install and run apache2 server only that group of instances. Show how you verify the apache2 servers are running on only the correct group of instances.
Â
Hint: You will need to dynamically create the inventory file for the new hosts.
http://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html
Â
3. Provide a pdf ReadMe file which specifies any instructions necessary to correctly run your python script used to run your 2 YAML playbooks. Include screenshots of the running python script and YAML playbooks, if working, for different user input values. Indicate any non- functional sections. You can use the windows âSnipping Toolâ to crop images from your screen.