Wing Tips: Remote Python Development on AWS with Wing Pro

Mar 24, 2020


In this Wing Tip we'll start looking at how to use Wing Pro to remotely develop Python code running on an AWS instance. With minimal configuration, Wing Pro can edit, debug, test, inspect, and navigate Python code residing on an AWS instance, as if it were on the local host.

Minimum Requirements

You will need an AWS instance that has Python installed on it, is running 32-bit or 64-bit Intel Linux, and that you can connect to using OpenSSH or PuTTY. PuTTY is recommended on Windows because it tends to be prone to fewer problems. You will need the following in order to configure Wing Pro to use your AWS instance:

(1) The user name and static IP address or DNS name used to connect to the AWS instance. Amazon Lightsail typically uses an IP address while EC2 and other variants of AWS may provide a DNS name as well. The static IP address will work in any case.

(2) The SSH key pair in a *.pem file, as downloaded from AWS.

If you do not already have Wing Pro installed, download it now.

Setting up AWS

If you already have an AWS instance to work with, you can skip this section.

Amazon Lightsail is the easiest way to get an AWS instance, in about 5 minutes. You will need to set up an account. Then create a Linux/Unix instance, selecting the OS Only option and the most recent Ubuntu or any other Intel Linux with Python 2 or 3 on it.

While setting up your instance, you can download your SSH key pair under the AWS SSH key pair manager. You'll need this on your local machine, where Wing is running, in order to be able to connect to the instance.

After the instance is created, it will remain in pending state for a minute or so. Once it is up and running, create a static IP address under the Network tab in the AWS Lightsail management area and attach it to your instance.

At this point you have all that is needed to start using Wing Pro with AWS: (1) The SSH key pair that you downloaded, and (2) the user name and IP address, which are shown on the Lightsail instance management page.

Testing the SSH Connection

Before trying to use your new instance from Wing Pro, you should first try to connect using ssh or PuTTY's plink.exe on the command line, to make sure those are working. This is important because Wing invokes those command lines to connect to the instance.

OpenSSH

On Linux or macOS using ssh, you need to make your *.pem SSH key pair file readable only by the user running Wing, for example with:

chmod 600 aws.pem

Otherwise, ssh will reject it as potentially compromised.

Once that is done, try connecting as follows, substituting the actual path to your downloaded SSH key pair and your instance's username and IP address or DNS name:

ssh -i /path/to/mykey.pem ubuntu@11.22.33.44

You will be asked to add the instance's identity to your known hosts file, which you should do by typing yes. If this is not done, ssh will fail to connect and Wing will also not be able to connect to the instance.

PuTTY

With PuTTY on Windows, you will need to first convert the SSH key to a format that PuTTY can use. This is done by launching puttygen, pressing the Load button to read the *.pem SSH key file you downloaded from the AWS management site, and then using Save Private Key to write a *.ppk file.

Then you invoke plink.exe to connect to the AWS instance as follows, substituting in the actual path to your downloaded SSH key pair and the correct username and IP address or DNS name for the AWS instance:

plink.exe -i C:\path\to\mykey.ppk ubuntu@11.22.33.44

You will be asked to accept the AWS instance's identity the first time you connect, and this must be done before Wing's remote development support will work with the AWS instance.

Creating a Wing Project

Now you're ready to create a project in Wing Pro. This is done with New Project from the Project menu. Select Connect to Remote Host via SSH as your project type. Then enter an identifier for the remote host (any short string to identify it in Wing's UI), and the user name and IP address or DNS name used to connect to the host:

/images/blog/aws-1/new-project.png

As in the above example, Python Executable will usually be Use default, which first tries python3 and then python. If Python is not on the PATH on your AWS instance or you want to specify a particular Python executable or activate a virtual environment, you can do this here.

You will also need to point Wing at the SSH key pair file you downloaded from AWS earlier. This is done under the Options tab using the Private Key field as follows:

/images/blog/aws-1/private-key-file.png

Pressing OK in the New Project dialog will create and configure the project, connect to the remote instance, install Wing's remote agent, and then offer to add source directories to the project or save the new project file:

/images/blog/aws-1/new-project-confirm.png

If you already have source code on the AWS instance, press Add Directory one or more times to add directories to the project. Typically, you want to add the directories that contain code you plan to work on, and leave out directories that contain Python, the standard libraries, and other modules and packages that you may use. Wing can find those as needed, through the Python Path.

If you are working with a blank new AWS instance, add the home directory to your project to get started. This can be changed later as needed.

Finally, save the project to local disk. The project is now ready to use.

Testing a Hello World

To try out a simple example of editing and debugging code on the remote AWS instance, create a file helloworld.py temporarily on the instance. This is done by right-clicking on one of the files in the Project tool in Wing Pro and selecting Create New File. Enter the file name (in some key bindings this is in the data entry area at the bottom of Wing's window) and type or paste the following into the new file:

import time
print("Hello World! {}".format(time.time()))

After saving the file, set a breakpoint on the second line by clicking on the leftmost margin in the editor:

/images/blog/aws-1/breakpoint.png

Then select Starting/Continue from the Debug menu to start debug, or use the green play icon play in the toolbar.

There is a slight delay to get the process started, depending on your network distance from the AWS instance, but then you should see Wing stop on the breakpoint:

/images/blog/aws-1/breakpoint-stop.png

There's not much to see here, but you can poke around a little in the live runtime state of the paused debug process, using Wing Pro's Debug Console, from the Tools menu:

/images/blog/aws-1/debug-console.png

Once you continue debugging, the process will exit and print to the Debug I/O tool:

/images/blog/aws-1/debug-io.png

That's it for now! We'll be back soon with more Wing Tips for Wing Python IDE.

As always, please don't hesitate to email support@wingware.com if you run into problems or have any questions.



Share this article: