Let’s start with how to use python code in AWS EC2:
Use Python Code in AWS
To use a python code in AWS, you have to create an EC2 instance for that, click on the “Launch Instance” button:
You need to give the name of your instance and then select the machine image for the virtual machine you will be using:
Then scrolling down a little and from there you have to select the instance type and create a key pair for the connection purposes and then click on the “Launch Instance” button to create an EC2 instance:
After the creation of the EC2 instance simply select the instance and click on the “Connect” button:
On this page select the “SSH client” and copy the command mentioned in the screenshot below:
Simply paste the command in the Command prompt or PowerShell and then change the path for the key pair from your PC:
After the connection to the virtual machine, simply use the following command to check if Python is installed or not:
This command will show you if python can be used or not:
Now use the following command to install the “pip” for python:
This command will install the pip for python:
After the installation, let us get inside the pip to check which directories are available and for that, use the following command:
This command will show you what is inside the python-pip:
Install the HTTP server by using the following command:
This command will install the Apache server:
After that, use the following commands to start the HTTP server, which will allow us to deploy our code:
systemctl enable httpd
These commands will activate the HTTP server:
After these services are activated, you can deploy python code using the following command:
This command will create a python file in which you can enter the python code and then type “:wq!” to save the file:
After creating a python file, you can use the following command to check what is the location of our python file:
This will tell us the location for our python file:
You have successfully used the python code in AWS:
Conclusion
To use a python code in AWS simply create an EC2 instance and then connect with the virtual machine. Once the connection is established with the virtual machine, you can use commands to install and activate different services required for using a python code. After all the services are in the “Active” state, use the commands to create a python file and then write a code on it. This post has taught you the process of how to use a python code to AWS.