├── CONTRIBUTING.md ├── README.md └── VPCs ├── create_vpcs_and_subnets.py └── list_vpcs.py /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute to this project 2 | 3 | ## Getting started 4 | Anyone can contribute to this project despite your python skill level(Beginner, Intermediate or Expert) 5 | 6 | If you are a newbie to open source, you can learn [ how to contribute to projects](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github) 7 | 8 | ## Opening an issue 9 | - If you have suggestions on scripts feel free to open an issue. 10 | Please search for your issue or question briefly in our issues before opening a new one to help us avoid duplicates. 11 | - If you are experiencing any bug in any of the scripts, feel free to open an issue. 12 | 13 | ## Fixing an Issue 14 | Please indicate in a comment if you wish to resolve an existing issue. This is to abstain from having more than one person working on a particular issue. 15 | 16 | ## Creating Pull request 17 | 1. Fork this repo, then clone it 18 | ``` 19 | $ git clone https://github.com/FaithKovi/Automation-with-python.git 20 | $ cd Automation-with-python 21 | $ git remote add upstream https://github.com/FaithKovi/Automation-with-python.git 22 | ``` 23 | 2. Create a new branch 24 | ``` 25 | $ git checkout -b my-new-branch 26 | ``` 27 | 3. Make your changes 28 | 29 | 4. Commit your changes. Use a descriptive commit message 30 | ``` 31 | $ git add . 32 | $ git commit -s -m "commit message" 33 | $ git push -u origin my-new-branch 34 | ``` 35 | 5. Submit a pull request 36 | 37 | Once we have a chance to review your PR, it can either be marked as "needs review" and specific feedback will be provided or we can complete the pull request. 38 | 39 | ## Syncing with the repository 40 | Keep in mind to regularly synchronize your fork with the main branch. To do this: Ensure you are in the root folder of the project and the branch should be main branch and type 41 | ``` 42 | $ git remote add upstream https://github.com/FaithKovi/Automation-with-python.git 43 | ``` 44 | Now that your upstream is set up on your local machine, whenever you need to create a new branch to make changes, make sure your main branch is in sync with the main repository by typing: 45 | ``` 46 | $ git pull upstream master 47 | $ git push origin master 48 | ``` 49 | 50 | ## Resources 51 | - [What is Open Source](https://opensource.com/resources/what-open-source) 52 | - [How to contribute to Open Source](https://opensource.guide/how-to-contribute/) 53 | - [How to write a good commit message](https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/) 54 | 55 | 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Automation-with-python 2 | 3 | This repository contains python automation scripts for Cloud 4 | 5 | ## VPC 6 | - [x] Create VPCs and Subnets 7 | - [x] List VPCs (ID, State and Tag Name) 8 | 9 | *Note: This will be updated once a new script is added* 10 | 11 | ## Contributing to this project 12 | 13 | To contribute to this project keep the rules found in our [CONTRIBUTING.md](https://github.com/FaithKovi/Automation-with-python/blob/main/CONTRIBUTING.md) document. Even if this is your first open source contribution, anyone from novice to expert, is welcome to contribute to this project. 14 | 15 | -------------------------------------------------------------------------------- /VPCs/create_vpcs_and_subnets.py: -------------------------------------------------------------------------------- 1 | import boto3 2 | 3 | # create aws client and resource 4 | ec2_client = boto3.client('ec2', region_name="us-east-1") 5 | ec2_resource = boto3.resource('ec2', region_name="us-east-1") 6 | 7 | # create new vpc 8 | new_vpc = ec2_resource.create_vpc( 9 | CidrBlock="10.0.0.0/16" 10 | ) 11 | 12 | # create two new subnets 13 | new_vpc.create_subnet( 14 | CidrBlock="10.0.1.0/24" 15 | ) 16 | new_vpc.create_subnet( 17 | CidrBlock="10.0.2.0/24" 18 | ) 19 | 20 | # create tags for the vpc created 21 | new_vpc.create_tags( 22 | Tags=[ 23 | { 24 | 'Key': 'Name', 25 | 'Value': 'my-vpc' 26 | }, 27 | ] 28 | ) 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /VPCs/list_vpcs.py: -------------------------------------------------------------------------------- 1 | import boto3 2 | 3 | # create aws client and resource 4 | ec2_client = boto3.client('ec2', region_name="us-east-1") 5 | ec2_resource = boto3.resource('ec2', region_name="us-east-1") 6 | 7 | # list vpcs in the configured region 8 | available_vpcs = ec2_client.describe_vpcs() 9 | vpcs = (available_vpcs["Vpcs"]) 10 | 11 | for vpc in vpcs: 12 | print(f"VPC ID: {vpc['VpcId']}") 13 | if 'Tags' in vpc: 14 | for tag in vpc['Tags']: 15 | if tag['Key'] == 'Name': 16 | print(f"VPC Name: {tag['Value']}") 17 | else: 18 | print("VPC Name: This VPC has no tag name.") 19 | cidr_block_assoc_sets = vpc["CidrBlockAssociationSet"] 20 | for assoc_set in cidr_block_assoc_sets: 21 | print(assoc_set["CidrBlockState"]) 22 | --------------------------------------------------------------------------------