PyCharm setup for AWS automatic deployment
In this post we will learn steps to perform PyCharm setup for AWS automatic deployment.
N.B: This is only possible with PyCharm Professional Edition
Download link
Launch an AWS (ubuntu) instance
-
Go to
servicesthenEC2underCompute
-
Then click on
Launch Instance
-
select the
Ubuntu Imagefor the Instance.
Generate key pairs for authentication (instance)
-
Create a new key pair and provide a name for it.
Should click on download and save it to a accessible location else thepycharm_aws_tut.pemfile won't be available later to download.
-
Click
Launch Instancesand thenview instances.
Soon the instance would be launch and update frompendingstatus torunningstatus and you may provide aname(anything under 255 characters) likepycharm_aws
Assign security group policies for accessing instance via command line or PyCharm.
- Click on
Security GroupsunderNetwork & SecuritythenCreate Security Group
- Fill in the form for security group and from
Actionsclick onEdit inbound rulesto giveSSHandHTTP.
N.B: Port is the value on which you wish to access your web app.
SSH to the EC2 instance using below command.
- Make note of the
Public DNSof that instance and theuser_name, by default the username isubuntuforubuntu instances.
sample: ssh -i /path_to_key/my_key.pem user_name@public_dns_name
Update file permissions: chmod 400 pycharm_aws_tut.pem.
Then execute: ssh -i pycharm_aws_tut.pem ubuntu@ec2-18-218-197-98.us-east-2.compute.amazonaws.com
N.B: Make sure your current directory has pycharm_aws_tut.pem file.
Congratulations you are connected your AWS EC2 Ubuntu Instance via Command line.
Create Flask app on my local system.
-
Create a file named as
my_aws_script.py(this is your flask script)
-
Add below lines of code.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello World 1"
@app.route('/index')
def index():
return "Hey This is an index page"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=80)
PyCharm settings to use remote python interpreter.
-
Go to
File->Settings->Project Interpreterand add a new interpreter.
-
Click on
+to add a new python interpreter and then click onSSH interpreter
-
Provide
Public DNSin HOST andubuntuasusername
-
Click
Nextand add thepycharm_aws_tut.pemfile.
-
Update python interpreter by passing the path of python on your ubuntu instance machine.
-
You may get this by running
which python3on command line of instance
-
Sync Folders
-
Click
Okand againOk.
Automatically deploy flask app on remote.
- Now click on
Tools->Deployment->Configuration
fill in the form as per the screenshot and then clickTest SFTP Connection
Mapping between local directory and remote directory.
- check
Mappingtab and makelocal pathandremote pathare the ones you wish toSync& click ok. - Now, go to
Tools->Deployment->Automaticand click to enable Automatic Deployment. - Soon background task would start running and sync the two locations.
Run the app on remote.
Execute below commands on the remote machine.
sudo apt-get udpateon remote machine.sudo apt-get install python3-pippip3 install flask
Check by executingpip3 freezeif flask is installed.
Then run the flask application.sudo python3 my_aws_script.py
Access the app via browser.
-
Copy and paste the Public DNS of the instance in the browser.
-
Access
/index

Hey AB Abhi,
Thank you very much for the post. This post is really helpful to deploy AWS in pyCharm on Ubuntu.
However, in my organization we’re prompted to work on Windows OS. I see, username is Ubuntu for new server configuration in SSH interpreter.But, in our case what would be the username for same thing, since we work on Windows OS.
The other thing is, in my EC2, Public DNS(IPV4) field is blank wheres Private DNS has some value. How can go ahead in such situation to deploy AWS in pyCharm.
Thanks!
Thank you Siddhesh.
For windows the username is Administrator
and Redhat the username is ec2-user.