- This lab walks you through the steps to create an AWS Cloud9 EC2 development environment and run python code in the environment.
- You will practice using AWS Cloud9.
- Duration: 30 minutes
- AWS Region: US East (N. Virginia).
- AWS Cloud9 is an integrated development environment or IDE.
- The AWS Cloud9 IDE offers a rich code-editing experience with support for several programming languages and runtime debuggers. It also has a built-in terminal with a preconfigured CLI.
- It contains a collection of tools that you use to code, build, run, test, and debug software.
How does AWS Cloud9 Work?
- We use the AWS Cloud9 IDE, running in a web browser on your local computer, to interact with your AWS Cloud9 environment.
- A computing resource like an EC2 Instance or our own server connects to that environment.
- Our work is stored in an AWS CodeCommit repository or another type of remote repository.
- Log into the AWS Management Console.
- Create an AWS Cloud9 development environment.
- Go through the Cloud9 IDE.
- Install Python using the terminal.
- Create a python file and add the code.
- Run the python file.
Task 1: Launching Lab Environment
- Launch the lab environment by clicking on . Please wait until the lab environment is provisioned. It will take less than 2 minutes to provision the lab environment.
- Once the Lab is started, you will be provided with IAM user name, Password, AccessKey and Secret Access Key.
- Click on the , AWS Management Console will open in a new tab.
- In the AWS sign in page, the Account ID will be present by default.
- Leave the Account ID as default. Do not remove or change the Account ID otherwise you cannot proceed with the lab.
- Copy and paste the IAM user name and Password into AWS Console. Click on Sign in to log into the AWS Console.
Note : If you face any issues, please go through FAQs and Troubleshooting for Labs.
Create an AWS Cloud9 Development Environment
- Navigate to and search for Cloud9 and select it.
- Choose the Create Environment button. If you do not have any AWS Cloud9 environments yet, the button is shown on a welcome page.
- On the Name environment page, for Name, enter a name for your environment.
- Name: whiz_env
- To add a description to your environment, enter it in Description.
- Description: Creating a new Cloud9 Environment
- Choose the Next step.
- On the Configure settings page, for Environment type, choose to Create a new EC2 instance for the environment (direct access) which Launches an Amazon EC2 instance that AWS Cloud9 can connect to directly over SSH.
- For Instance type, choose t2.micro (1 GiB RAM + 1 vCPU)
- Under the Platform, choose the type of Amazon EC2 Instance as Amazon Linux. AWS Cloud9 creates the instance and connects it to the environment.
- Under the Cost-saving setting, leave it as default.
- Leave the Network settings (advanced) as default. Click on Next Step.
- On the Review page, choose to Create environment. Wait while AWS Cloud9 creates your environment. This can take several minutes.
- Once AWS Cloud9 creates your environment, it displays the AWS Cloud9 IDE for the environment.
- If AWS Cloud9 doesn’t display the IDE after at least five minutes, there might be a problem with your web browser or instance or others.
Go through the Cloud9 IDE
- Go through the Cloud9 IDE.
- To go to the cloud9 dashboard, click on Go to Your Dashboard.
- You can click on Open IDE anytime to go to the environment.
Install Python Using the Terminal
- In a terminal session in the AWS Cloud9 IDE, confirm whether Python is already installed by running the python –version command.
- To start a new terminal session, on the menu bar choose Window, New Terminal.
- Run the yum update command to help ensure the latest security updates and bug fixes are installed.
- sudo yum -y update
- If python is not present, Install Python by running the install command.
- sudo yum -y install python36
Create a Python File and Add Code
- In the AWS Cloud9 IDE, create a file with the following content and save the file with the name hello.py. To create a file, on the menu bar choose File, New File. To save the file, choose File, Save.
- print(“Hello World!”)
- print(“The sum of 2 and 3 is 5.”)
- The screenshots are mentioned below.
Run the Python File
- In the AWS Cloud9 IDE, on the menu bar choose Run, Run Configurations, New Run Configuration.
- On the [New]-Stopped tab, enter hello.py in the command and choose Run.
- You can check the Output and compare it with your code.
Completion and Conclusion
- You have successfully created an AWS Cloud9 Development Environment
- You have successfully gone through the Cloud9 IDE.
- You have successfully installed python using the terminal.
- You have successfully created a python file and added the code.
- You have Run the python file.
- Once the lab steps are completed, please click on the button on the right-side panel.
- This will validate the resources in the AWS account and shows you whether you have completed this lab successfully or not.
- Sample output :
- Let us delete the created resources.
- In the list of environments, for the environment, you want to delete, Choose the title of the card for the environment. Then choose Delete.
- In the Delete dialog box, type Delete, and then choose Delete.
- AWS Cloud9 also terminates the Amazon EC2 instance that was created and connected to that environment.