Explore Courses Blog Tutorials Interview Questions
0 votes
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.2k 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 username@instance_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\ [email protected]:/home/ec2-user


  • path_to_pem_file : C:\Users\intellipaat\Desktop\ohio.pem
  • path_to_python_script : C:\Users\intellipaat\Desktop\
  • username: ec2-user
  • instance_public_DNS :
  • 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:


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

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer

Browse Categories