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\hello.py [email protected]:/home/ec2-user
Here,
- 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:
ls
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