Table of contents
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.
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.
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.
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.
Provide the environment Name (Description is optional) and click Next step button.
At the next step you may change environment type, EC2 instance type, hibernation, networking and other settings.
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.
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.
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
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:
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:
- Run it directly from the Cloud9 IDE
- 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.
Now close the program execution output tab.
Now, let’s run the same program from the terminal.
There are two ways of doing this:
- Run the program using
- 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:
You should see the same result:
And finally, let’s make the program executable and run it as regular executable.
chmod command to make the program executable (
chmod +x hello_aws_world/main.py
Now, you can run it as a regular executable command in Linux:
Expected result is down below: