How to setup Cloud9 IDE for Python for cloud automation

There are many integrated development environments (IDEs) available today which allows you to develop code in any programming language on your local machine. The most well-known examples of such IDEs are: Microsoft Visual Studio Code, PyCharm, and IntelliJ IDEA. But the goal of this article is to cover another solution – AWS Cloud9 IDE, a cloud-based IDE that allows you to write, run, test and debug your code with just a browser. It includes a code editor, debugger, and terminal, supports popular programming languages, including Python, JavaScript, PHP, and many others. In this article I’ll cover how to set up Cloud9 IDE to start Python cloud automation journey.

Benefits of using Cloud9 IDE

There are a lot of useful features at Cloud9 IDE, which might be interested in. Down below I listed benefits which are the most important for myself, but I definitely encourage you to use the link and check all of them.

Browser based IDE

As I’ve already mentioned, Cloud9 is a cloud based IDE, which you’re using in your browser. That means, that the actual code is stored on EC2 instance in the AWS cloud and you can write, run, and debug applications with just a browser, without needing to install or maintain a local IDE.

Cloud9 IDE EC2 instance can be accessed in various different ways.

Direct access option will launches an Amazon EC2 instance that AWS Cloud9 service can connect to directly over SSH. This is the most popular setup for the beginners.

1. How to set up Cloud9 IDE for Python for cloud automation - Direct access

Access via Systems Manager allows to launch an EC2 instance that doesn’t require any open inbound ports; AWS Cloud9 connects to the instance through AWS Systems Manager. This is a little bit complex, but more secure setup.

2. How to set up Cloud9 IDE for Python for cloud automation - Access via Systems Manager

SSH connection option allows you to use Cloud9 IDE in already existing server. This setup requires some requirements to be satisfied before you can start using this option.

For all next Python tutorials in this blog I recommend you to move forward with the first Cloud9 IDE deployment option as the most easy and straight forward to setup.

Development environment sharing

You can share your development environment with your team and start pair programing session. While collaborating, your team members can see each other type in real time, and instantly chat with one another from within the IDE. This feature is very handy when I need to help others to resolve code issues.

4. How to set up Cloud9 IDE for Python for cloud automation - Team collaboration

Seamless integration with AWS

You do not have to configure any additional permissions to access cloud resources within your AWS account and services as by default your user account permissions are inherited. That means, you can run any command from the terminal or make an API calls from your code and those will be executed with your permission.

Out of the box, you’re getting the following benefits:

  • You don’t need to store the permanent AWS access credentials of an AWS entities
  • You don’t need to manually set up, manage, or attach an instance profile to the Amazon EC2 instance that connects to the environment.
  • AWS Cloud9 continually renews its temporary credentials, so a single set of credentials can be used only for a limited time. This is an AWS security best practice.
  • AWS Cloud9 puts additional restrictions on how its temporary credentials can be used to access AWS actions and resources from the environment. This is also an AWS security best practice.

Of course, there are many other ways to configure Cloud9 IDE permissions, but this topic is out of scope for this article.

Creating Cloud9 IDE environment

In this section I’ll show you how easy it is to launch Cloud9 IDE and start using it.

First of all, navigate to the Cloud9 IDE console: https://us-east-2.console.aws.amazon.com/cloud9/ and click the Create environment button.

5. How to set up Cloud9 IDE for Python for cloud automation - Launch Cloud9 IDE - Step 1

Provide the environment Name (Description is optional) and click Next step button.

6. How to set up Cloud9 IDE for Python for cloud automation - Launch Cloud9 IDE - Step 2

At the next step you may change environment type, EC2 instance type, hibernation, networking and other settings.

7. How to set up Cloud9 IDE for Python for cloud automation - Launch Cloud9 IDE - Step 3

If you’re experienced use, feel free to adjust the settings according to your needs.

For the beginners, I recommend to proceed with default settings.

Click the Next step button as soon as you’re ready.

8. How to set up Cloud9 IDE for Python for cloud automation - Launch Cloud9 IDE - Step 4

Finally, review your settings and click Create environment button.

The launching process will take a couple of minutes, and finally, you’ll see your IDE up and running.

9. How to set up Cloud9 IDE for Python for cloud automation - Cloud9 IDE up and running

Now, you’re ready to start your Python cloud automation journey.

How much does the Cloud9 IDE cost

Every unused Cloud9 IDE will be automatically paused, when you’re not active and then started, when you decided to resume your work. That allows you to pay only for what you use at the normal AWS rates for consumed resources.

AWS pricing is a subject to change, but to the moment of writing this article, pricing example illustrates, that if you’re willing to use the default settings running an IDE for 4 hours per day for 20 days in a month with a 30-minute auto-hibernation setting your monthly charges for a 90 hours usage roughly would be a couple of dollars a month.

Hello AWS World example

Let’s create a simple “Hello AWS World” Python program, that will print message to the standard output.

To create this simple program:

  • Delete the README.md file
  • Create hello_aws_world folder inside your project structure
  • Create an empty main.py file inside hello_aws_world folder
10. How to set up Cloud9 IDE for Python for cloud automation - Hello AWS World - Project structure

Now open the main.py file and type the following code there:

#!/usr/bin/env python3

print("Hello AWS World")

Here’s how the final result should look like:

11. How to set up Cloud9 IDE for Python for cloud automation - Hello AWS World - Code

Here, what we just wrote:

  • #!/usr/bin/env python – this is required string only if you’re willing to make this program executable from the console as a regular program; this string allows shell to use env utility to find path to python3 interpreter, which will be used to run your program
  • print("Hello AWS World") – is a regular Python 3 print function, that allows you to print something to the standard output (normally, a terminal); in our case it will print “Hello AWS World” message.

Running the example

To run your program you have two options:

  1. Run it directly from the Cloud9 IDE
  2. Run it from the terminal

To run the program from the IDE, click Run button. If you do not have any typos, you should see a “Hello AWS World” message.

12. How to set up Cloud9 IDE for Python for cloud automation - Hello AWS World - Run from IDE

Now close the program execution output tab.

13. How to set up Cloud9 IDE for Python for cloud automation - Hello AWS World - Close execution results tab

Now, let’s run the same program from the terminal.

There are two ways of doing this:

  • Run the program using python3 command
  • Make the program executable and run it as a regular executable

To run the program using python3 command, execute the following command in the terminal:

python3 hello_aws_world/main.py

You should see the same result:

14. How to set up Cloud9 IDE for Python for cloud automation - Hello AWS World - Run using python3 command

And finally, let’s make the program executable and run it as regular executable.

Use chmod command to make the program executable (-x argument):

chmod +x hello_aws_world/main.py

Now, you can run it as a regular executable command in Linux:

./hello_aws_world/main.py

Expected result is down below:

15. How to set up Cloud9 IDE for Python for cloud automation - Hello AWS World - Run as executable

Summary

In this article we’ve covered how to set up Cloud9 IDE for Python for cloud automation. AWS Cloud9 IDE – a cloud-based IDE that allows you to write, run, test and debug your code with just a browser. Cloud9 IDE includes a code editor, debugger, and terminal, supports popular programming languages, including Python, JavaScript, PHP, and many others.

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment