0 votes
1 view
in AWS by (12.9k points)

I understand nearly nothing to the functioning of EC2. I created an Amazon Web Service (AWS) account. Then I launched an EC2 instance.

And now I would like to execute a Python code in this instance, and I don't know how to proceed. Is it necessary to load the code somewhere in the instance? Or in Amazon's S3 and to link it to the instance?

Where is there a guide that explain the usages of instance that are possible? I feel like a man before a flying saucer's dashboard without user's guide.

1 Answer

0 votes
by (18.6k points)

Using SCP (Secure Copy Protocol), you can transfer files between your local and remote machines. 

To run python code in your instance, follow the below-mentioned steps:

Step 1: Launch an Amazon Linux instance, SSH into it and install Python in it  using the following commands:

sudo yum update

sudo yum install python3.7

Step 2: Open command line terminal on your local machine and run the following command.

scp -i path_to_pem_file path_to_python_script [email protected]_public_DNS:/path_to_copy

For example, following is the command that I used:

scp -i C:\Users\intellipaat\Desktop\ohio.pem C:\Users\intellipaat\Desktop\hello.py [email protected]:/home/ec2-user


  • path_to_pem_file : C:\Users\intellipaat\Desktop\ohio.pem
  • path_to_python_script : C:\Users\intellipaat\Desktop\hello.py
  • username: ec2-user
  • instance_public_DNS : ec2-3-19-65-215.us-east-2.compute.amazonaws.com
  • path_to_copy : /home/ec2-user

Once you run this SCP command on your cmd, your file will be copied to your instance.

Step 3: Go back to your putty terminal and verify that the file has been copied to your instance by running the following command:


You should see the file there in your instance

Step 4: Run this file using the following command:

python3 file_name.py

And that's it, you will see the output after your run this command

Welcome to Intellipaat Community. Get your technical queries answered by top developers !