CS6650 Building Scalable Distributed Systems
This lab is designed to guide you to create an EC2 instance on AWS running AWS Linux, install Tomcat, and deploy your webserver built using Go-Gin framework onto it.
AWS Linux 2 is the version to use. You may choose another Linux instance but will be on your own. AWS Linux 2023 should be ok but we haven’t tested it.
Completed the two tutorials in Lab 0.
https://go.dev/doc/tutorial/getting-started
https://go.dev/doc/tutorial/web-service-gin
Note for second tutorial. change the address of your server in main function to remove the localhost reference as below.
Original : router.Run("localhost:8080")
Change to: router.Run(":8080")
This is to enable the server to run on EC2.
Basically we want to cross compile the Go-Gin codes coded on Your local machine into binary executable file that you can run on EC2 directly.
After you build and test your code. open a bash terminal, navigate to the main directory of your Go-Gin code file (where your main.go reside),
Run the following command to cross-compile your code
GOOS=linux GOARCH=amd64 go build -o <your-filename> main.go
Get AWS account up and running - you should have an AWS Academy invitation
Sign into the AWS Academy Learner Lab. Hit the ‘Start’ button for any of the labs, and watch the alien-like V symbol spin for a long time. When it finished the ‘AWS’ logo on the left should be green, Hit this and it will throw you into an AWS Console Window. From that window you should be able to follow the instructions in the next step. For visual guide reference, you can check here
Launch a free tier AMI running Amazon Linux 2023 or Amazon Linux 2 on us-west2 (it should be available)
You must configure access to your virtual machine uisng AWS Security Groups. This is a good overview if you are unfamiliar
Make sure you have configured your security group that allows traffic on:
port 8080 as a Custom TCP Rule (Same port as your Go-Gin server) port 22 for ssh.
Make port 22 accessible from “My IP” for when you are working from home. On campus you will need to redo this rule each time as your allocated IP address might change
For port 8080, on the Seattle campus, AWS would see the following incoming IP CIDRs, so create Custom TCP Rules for the following addresses. These rules should always work on campus: 63.208.141.34/29 63.208.141.234/29
Alternatively, make port 8080 accessible from My IP as well if you testing from home. As your ISPs may give you different IP address from CIDR blocks above.
Under no circumstances open any port to everywhere. You will get hacked and lose your account.
ssh into your instance, These instructions should work. Alternatively, check the official AWS Website here. Basically the command looks like below:
~~~
ssh -i your-amazon.pem ec2-user@instance-address
~~~
Follow these instruction for the first 5 steps
ignore the instructions to configure the firewall service at the end of Step 3.
ignore setting up httpd - we are using tomcat instead
Tomcat listens on port 8080, so in your browser go to http://{your public IP address}:8080 and you should see the Tomcat homepage. Hit the manager app button and on the homepage and you should be able to log in with your credentials. If you can’t and get a 403 error, follow this link to fix it.
Once you get this far, life looks pretty good. First mission accomplished! In 3 weeks you’ll be able to do all this in your sleep.
Some notes based on first experience with the Learner Lab:
After SSH into EC2, make a directory of your choice using mkdir command
#create your directory, if permission denied, add sudo
(sudo) mkdir <your_dir_name>
#run following command to allow permission to upload files
#if permission denied, add sudo
(sudo) chmod -R 777 <your_dir_name>
Open a command prompt windor from your local machine, and use scp to copy the file onto EC2
sudo scp -i <path to your pem file for aws private key, include.pem extension> <path to your executable binary cross-compiled> ec2-user@<EC2_IP_ADDR>:<folder of your choices>
Note the whitespace, if I separate the command by whitespace I should see something like
sudo
scp
-i
<path to your pem file for aws private key, include.pem extension>
<path to your executable binary cross-compiled>
ec2-user@<EC2_IP_ADDR>:<folder of your choices>
Notes for above commands
Now you can try run your go server, navigate to the directory where your upload the file
#run your go-server file
./<your-filename>
do this to change permissions if you get permission denied
sudo chmod -R 777 <your-filename>
Once you get this far, life looks pretty good. First mission accomplished! In 3 weeks you’ll be able to do all this in your sleep.
Some notes based on first experience with the Learner Lab:
Here is some troubleshooting guide if something is not working.
We will be using AWS Academy Learner Labs for this course.
AWS Academy Learner Lab - Foundation Services provides a long-running sandbox environment for ad hoc exploration of AWS services. Within this class, you will have access to a restricted set of AWS services. Not all AWS documentation walk-through or sample labs that operate in an AWS Production account will work in the sandbox environment. You will retain access to the AWS resources set up in this environment for the duration of this course. You are limited in budget ($100), so you should exercise caution to prevent charges that will deplete your budget too quickly. If you exceed your budget, you will lose access to your environment and lose all of your work.
Each session lasts for 4 hours by default, although you can extend a session to run longer by pressing the start button to reset your session timer. At the end of each session, any resources you created will persist. However, AWS automatically shuts EC2 instances down. Other resources, such as RDS instances, keep running. Keep in mind that AWS does not stop some AWS features, so they can still incur charges between sessions. For example, an Elastic Load Balancer or a NAT. You may wish to delete those types of resources and recreate them as needed to test your work during a session. You will have access to this environment for the duration of the class they enrolled you in. When the class ends, your access to the learner lab will also end.
When you stop/start your EC2 instance, the public IP address will change. The extract below is from stackoverlow.
Actually, When you stop/start your instance, the IP address will change. If you reboot the instance, it will keep the same IP addresses. Unfortunately, it is not possible for us to reassign the address to your instance as that address would have been released back into the pool used by other EC2 instances.
If you want to avoid this issue in the future, depending on your needs:
And from here
You are not billed for stopped EC2 instances.