Week 6.2— Setting Up
Setting up a FLASK/AWS Server through the Terminal
--
Sorry for the delay. Learning took much longer this time. So, today, we will be purchasing an instance on Amazon Web Services in order to grant access to our projects to everyone on the web.
In order to launch a web service, we will run our project on a server that can respond to our clients’ requests at any time.
In order to do that, we should:
- Keep the computer and the program on all the time
- Allow access to the service through a public IP address
Remember, a server is another way of calling a computer, and we can use our laptops as servers after allowing public access. However, for privacy and efficiency reasons, we will be purchasing an “EC2 instance” on Amazon Web Services, a cloud service platform.
Purchasing a Server
In order to purchase an AWS EC2 server, use the following snippet and follow the visual instructions below:
https://ap-northeast-2.console.aws.amazon.com/ec2/v2/home?region=ap-northeast-2
Accessing the Server
Now, let’s access the AWS EC2. On your Mac, go to Terminal and type in the following (to learn more about the Terminal, find this article).
Convert accessibility rights for the keypair:
sudo chmod 400 [keypair.pem]
Access with SSH
ssh -i [keypair.pem] ubuntu@[public IP address]
Setting up the Server
Using Filezilla, upload a python file named “test.py” with the following content:
print('hello world!!')
Then, if you type in
python3 test.py
on the Terminal, you’ll see “hello world!!” printed.
However, we do not want “python3” to be the command word; since we have just purchased the computer, we need to construct a proper server environment using the following commands:
First, download the following file (initial_ec2.sh) and upload to Filezilla.
https://s3.ap-northeast-2.amazonaws.com/materials.spartacodingclub.kr/web101/week5/initial_ec2.sh
Then, enter the following command into the Terminal:
sudo chmod 755 initial_ec2.sh
Run the file:
./initial_ec2.sh
Now, we should be able to use python, MongoDB, etc. on the Terminal.
Great. We can upload our project now…or can we? Let us figure out in the next post!
Fin.