top of page

Tutorial blog to use GitHub along with AWS Cloud9 (Part 1)

Updated: Oct 18, 2023

Learning Objective:

  • Learn to use GitHub along with Cloud9.

Prerequisites:

  • A GitHub account. To sign up for GitHub account click here

Step 1: In AWS Management Console, go to Cloud9 and create environment.


Enter the Name as MyENV and Description as Environment for Git. Open VPC settings and select Subnet as ap-south-1a default.

Leave all rest as default and create environment.


Step 2: Go to Github and login to your account. Click on the green button on the top left to create a new repository.


Give the repository name as Calculator and description as Simple Python calculator. Under Add. gitignore select Python and create repository.


Step 3: Open the environment we created in Step 1 in Cloud9.

Click on the source control icon then click on Clone Repository.

Go to the GitHub repository we created and click on Code. Click on the copy button to copy the repo URL and paste it in the Cloud9 text box and enter


Click on main in the bottom right and create new branch. Name that branch calc.

Step 4: To create a python script, click in New File from Template from File menu and select the Python File.

Paste the following code in the file.

Python code

# Function to add two numbers def add(x, y): return x + y # Function to subtract two numbers def subtract(x, y): return x - y # Copy first snippet here # Main program loop while True: # Display menu print("Options:") print("Enter 'add' for addition") print("Enter 'subtract' for subtraction") # Copy second snippet here print("Enter 'quit' to end the program") # User input user_input = input(": ") # Check if user wants to quit if user_input == "quit": break # Check for valid operation if user_input in ("add", "subtract"): num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) if user_input == "add": print("Result:", add(num1, num2)) elif user_input == "subtract": print("Result:", subtract(num1, num2)) # Copy fourth snippet here else: print("Invalid input")

Save as : Calculator.py. (Click on Calculator option in Save as as it represents the Git repo)

Step 5: Click on the + sign next to the Changes tab on the left to add all the changes.


Paste following 2 commands in the bash terminal. Replace 'your_github_username' with your username and similarly replace 'your_email' with your e-mail ID.

git config --global user.name your_github_username

git config --global user.email your_email

(In the above 2 commands, you may want to enter your username & email)

Now enter the message Calculator first commit in the message bar and press ctrl+enter. This commits the changes made.

Click the indicator that looks like a cloud in the lower left hand corner to push the changes to GitHub.

To push commits you will need to enter Git username and a security token in top left.

To create Git security token go to your account on GitHub and go to settings.

Go to Developer settings and create a security token. Enter your password, note as Calculator token and tick on all boxes when prompted. Choose Classic token.

Copy the given token and store it for further use. Now enter your GitHub username and

enter this token when asked for password while committing changes. This token can be

re-use again.



Step 6: After pushing changes enter the following snippets at the mentioned lines in Calculator.py in Cloud9.

Replace the below code on ‘# Copy first snippet here’ in the script:

# Function to multiply two numbers

def multiply(x, y):

return x * y


# Function to divide two numbers

def divide(x, y):

if y == 0:

return "Cannot divide by zero"

return x / y

Repeat the same process for Second, Third and Fourth snippet.

Replace the below code on ‘# Copy second snippet here’ in the script:

print("Enter 'multiply' for multiplication")

print("Enter 'divide' for division")

Replace the below code on the line that contains ‘if user_input in ("add", "subtract"):’ in the script:

if user_input in ("add", "subtract", "multiply", "divide"):

Replace the below code on ‘# Copy fourth snippet here’ in the script:

elif user_input == "multiply":

print("Result:", multiply(num1, num2))

elif user_input == "divide":

print("Result:", divide(num1, num2))


Note: Please take care to maintain proper indentation while adding these lines.

Save the file and refer to step 5 to add, commit and push changes to GitHub. Use the previously created security token to commit changes. For commit message write Calculator second commit.

This time there will be a round arrows symbol instead of cloud for push, use that.

You can review commits by going to the repository, changing branch to calc and clicking on commits.


Note: Delete Cloud9 environment, if it’s not to be used later.



Was this document helpful? How can we make this document better. Please provide your insights. You can download PDF version for reference.



For your aws certification needs or for aws learning contact us.






Recent Posts

See All
bottom of page