DEV Community

Revathi Joshi for AWS Community Builders

Posted on • Originally published at Medium

Create an inventory of AWS Services using Python

AWS Services

Welcome to my Python project!

I am learning Python and adding this to my learning experience in AWS! Writing a simple Python program, a combination of Python lists by name/index and functions like print, append, insert, and remove the variables.

Objectives

  • Create a list of AWS services using Python script -
    project_14.py

  • The list should be empty initially.

  • Populate the list using append and/or insert.

  • Print the list and the length of the list.

  • Remove two specific services from the list by name or by index.

  • Print the new list and the new length of the list.

Pre-requisites

  • AWS user account with admin access, not a root account.

  • Cloud9 IDE comes with Python installed.

Resources Used:

Certified Entry-Level Python Programmer Certification by ACloudGuru

I have also found these sites to be very helpful in understanding the basics of Python.

For number conversion tools to convert binary, decimal, hexadecimal and octal numbers to each other, used binaryhexconverter.

For Python Tutorials on Bitwise Operators (AND | OR | XOR | Complement/NOT | Left Shift | Right Shift), used YouTube Videos
of Amulya’s Academy.


Let’s get started!

You can find the complete code on my GitHub Repository.

I have used Cloud9 as IDE to write, run, and debug the Python code with just a browser. While working on this project, I stored the files generated in my Cloud9 IDE to GitHub repository outside of this EC2 VM, so that I would not loose my code if anything happens to this VM on AWS.

Steps of Implementing the Objectives

Create a list of AWS services using Python script

project_14.py

The list should be empty initially.

#!/usr/bin/env python3.7
# create a variable to hold a place in memory for the list of AWS services
aws_services = []
Enter fullscreen mode Exit fullscreen mode

Populate the list using append and/or insert.

  1. Using an ‘append’ method, I have used the following AWS services to create a list for demonstration purposes.
  • AWS Batch

  • Amazon CloudWatch

  • Amazon DynamoDB

  • Amazon Elastic Compute Cloud (EC2)

  • AWS Lambda

  • Amazon Simple Storage Service (S3)

# using 'append' method, add an object to the list
aws_services.append('Batch')
aws_services.append('CloudWatch')
aws_services.append('DynamoDB')
aws_services.append('EC2')
aws_services.append('Lambda')
aws_services.append('S3')
Enter fullscreen mode Exit fullscreen mode
  1. Using an ‘insert’ method, I have used the following AWS services to create a list by index

AWS Services list by index

# using 'insert' method, add an object to the list by index
aws_services.insert(0, 'Athena')
aws_services.insert(1, 'Aurora')
aws_services.insert(5, 'FSx')
Enter fullscreen mode Exit fullscreen mode

Print the list and the length of the list.

# print the list and the length of the list
length = len(aws_services)
print("This is the list of AWS services:", aws_services, " and the length of the list is: ", length)
Enter fullscreen mode Exit fullscreen mode

Remove two specific services from the list by name and/or by index.

# remove 2 services from the list by name
aws_services.remove('Athena')
aws_services.remove('S3')

# remove 2 services from the list by index
del aws_services[3]
del aws_services[4]
Enter fullscreen mode Exit fullscreen mode

Print the new list and the new length of the list.

# create variables to hold a place in memory for the list and new length of AWS services
new_list = list(aws_services)
new_length = len(new_list) 

# print the new list and new length of the list
print("This is the new list of AWS services: ", new_list, " and new length of the list: ", new_length)
Enter fullscreen mode Exit fullscreen mode

What we have done so far

Created a python script for a list of AWS Services by first populating it by append/insert methods, printing the list and the length of the list, removing specific services by name/index, and lastly printing the new list and the length of the new list.

It was fun working with Python and doing this project. I will post more articles as I learn to code my projects with Python.

Top comments (0)