Revised by Patrick Diamitani and Grok 3 Co-Pilot. Originally from AWS re/Start Lab: Module 108 – Hello World – Python | Download Guide
Overview
In this guide, you’ll set up AWS Cloud9, a cloud-based integrated development environment (IDE), to write and run a simple “Hello, World” Python program. This setup introduces you to Python development in the AWS ecosystem, providing a scalable, secure, and accessible environment for coding. Whether you’re a beginner learning to code or an experienced developer exploring AWS tools, this lab helps you understand how to leverage Cloud9 for Python projects. By the end, you’ll have a functional IDE, a working Python script, and the skills to troubleshoot common issues—all hosted on AWS.
Why it’s useful: AWS Cloud9 eliminates the need for local setup, offering a preconfigured environment accessible from any browser. It’s perfect for learning, prototyping, or collaborating on code in real time.
Prerequisites
Before starting, ensure you have:
- An AWS Account: Sign up at aws.amazon.com if you don’t have one.
- Basic Permissions: Your AWS user needs access to Cloud9 and EC2 (Cloud9 runs on an EC2 instance). Attach the AWSCloud9User policy or use an admin role.
- Web Browser: Chrome, Firefox, or Edge for accessing the AWS Console.
- No Local Tools Required: Cloud9 includes Python and a terminal—no need to install anything locally.
Step-by-Step Guide
Step 1: Log In to AWS and Access Cloud9
- What: Sign into the AWS Management Console and locate Cloud9.
- Why: This is your entry point to the cloud IDE.
- How:
- Go to console.aws.amazon.com.
- In the search bar, type “Cloud9” and select it from the Services menu.
- If no environment exists, click Create environment. Otherwise, select an existing one (e.g., reStart-python-cloud9) and click Open IDE.
- CLI Option: To list environments, use:
aws cloud9 list-environments - Tip: If the IDE doesn’t load, ensure pop-ups are enabled in your browser.
Step 2: Create a New Python File
- What: Set up a file to hold your Python code.
- Why: This file will contain your “Hello, World” script, teaching you file management in Cloud9.
- How:
- In the Cloud9 IDE, go to File > New From Template > Python File.
- An untitled file opens. Clear any default code.
- Click File > Save As, name it hello-world.py, and save it in /home/ec2-user/environment.
- Code Snippet:
python
# Empty file ready for your code - Note: The .py extension tells Cloud9 this is a Python script.
Step 3: Open a Terminal in Cloud9
- What: Access the built-in terminal to run commands.
- Why: The terminal lets you verify your environment and execute scripts.
- How:
- In Cloud9, click the + icon at the top and select New Terminal.
- Verify your directory with:
bash
pwd
Output: /home/ec2-user/environment. - Check Python versions:
bash
python3 –version
Expected: Python 3.6.x or higher.
- Why It Matters: Ensures you’re using Python 3, the modern standard.
Step 4: Write and Run Your “Hello, World” Program
- What: Code a simple Python script and execute it.
- Why: This confirms your setup works and introduces Python basics.
- How:
- Open hello-world.py from the left navigation pane.
- Add this code:
python
CollapseWrapCopy
print(“Hello, World”) - Save the file (File > Save).
- Click the Run (Play) button at the top of the IDE.
- Check the bottom pane for output: Hello, World.
- CLI Alternative: Run it manually:
bash
python3 hello-world.py - Visual Aid: Imagine the IDE split into three: file tree (left), editor (center), and output (bottom).
Step 5: Clean Up (Optional)
- What: Stop or delete your Cloud9 environment.
- Why: Avoid unnecessary costs since Cloud9 runs on EC2.
- How:
- In the AWS Console, go to Cloud9 > Environments.
- Select your environment and click Delete.
- CLI Option:
bash
aws cloud9 delete-environment –environment-id <your-env-id>
Real-World Use Cases
This Cloud9 setup isn’t just for labs—it’s a foundation for real projects:
- Web Development: Host a Flask or Django app in Cloud9, then deploy it to AWS Elastic Beanstalk.
- Extension: Add a requirements.txt and install dependencies with pip3.
- Team Collaboration: Share your Cloud9 environment with colleagues for pair programming.
- How: Use the “Share” feature in Cloud9.
- Data Science: Write Python scripts to analyze datasets, integrating with AWS S3 for storage.
- Example: Pull CSV files from S3 using boto3 and process them in Cloud9.
- CI/CD Pipelines: Prototype scripts for AWS CodePipeline, testing automation workflows.
Troubleshooting
Issue 1: Cloud9 IDE Won’t Open
- Symptoms: Blank screen or “Access Denied”.
- Solution:
- Check your IAM permissions—ensure AWSCloud9User is attached.
- Verify pop-ups are allowed in your browser settings.
- Debug with CloudWatch Logs: Go to CloudWatch > Logs > /aws/cloud9/.
Issue 2: Python Version Mismatch
- Symptoms: Running python –version shows Python 2.x, not 3.x.
- Solution:
- Use python3 explicitly:
bash
python3 hello-world.py - Update the default alias in the terminal:
bash
alias python=python3
- Use python3 explicitly:
Issue 3: “Hello, World” Doesn’t Print
- Symptoms: No output or syntax errors.
- Solution:
- Check for typos in print(“Hello, World”).
- Ensure you saved the file before running.
- Run manually in the terminal to isolate IDE issues:
bash
python3 hello-world.py
Issue 4: Environment Not Found
- Symptoms: Can’t locate reStart-python-cloud9.
- Solution:
- Create a new environment in Cloud9 with default settings.
- Use the CLI to list environments:
bash
aws cloud9 list-environments
Conclusion & Best Practices
You’ve now set up AWS Cloud9, written a Python script, and learned to troubleshoot common issues. This foundation opens doors to coding in the cloud with AWS. For optimization:
- Security: Use IAM roles instead of long-lived credentials in Cloud9.
- Scalability: Pair Cloud9 with Auto Scaling EC2 instances for larger projects.
- Efficiency: Save reusable scripts in S3 to access across environments.
Explore more at AWS Cloud9 Documentation. Happy coding on AWSAISetup.com!