EC2
Summary
Setting up
Instances
The EC2 setting up is pretty straight forward as you set up a standard virtual machine. Just follow the wizard and you will have a brand new VM on your hands.
Focus should be on
- SSH key pair (to be able to connect to it)
- Assigned security group should allow HTTP from anywhere and SSH from your IP address only
Key pairs are region-dependent. If the same key pair has to be shared betweem multiple regions, it must be uploaded manually regions by regions
Subnets
Instances must be attached to be subnet. As a primary network, the subnet cannot be changed. IP settings (dynamic IP assignments) can be changed by re-assigning a new IP. An instance is connected to a subnet thanks to an ENI: Elastic Network Interface
Sources:
Load balancer
New load balancers are:
- application load balancer: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html
- network load balancer: https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html
Comparison: https://aws.amazon.com/elasticloadbalancing/features/#Product_comparisons
Application load balancer
An application load balancer:
- a service, no instance to handle
- has a A record DNS name
- can be dual stack or IPv4 only
The balancing is done by adding listeners. A listener listens to a specific port and an action must be specified. Such actions can be forwarding to a target group or redirect.
A target group is a set of instances on one or multiple availability zones on a specific port.
Running a web application
Installation
Rails example:
- Start with the first of all:
sudo apt-get update
- Install Ruby. I was going the RVM route
- https://gorails.com/setup/ubuntu/18.04
- https://www.howtoforge.com/tutorial/ubuntu-ruby-on-rails/
- Install Rails via a simple
gem install rails
- PostgreSQL
pg
gem is a bit tricky:sudo apt-get install postgresql-client libpq5 libpq-dev sudo gem install pg
- As a non-root user, we cannot use the 80 port (any port below 1024 actually). Trick is to use port forward from 80 to 3000
sudo ufw enable
=> enable firewallsudo ufw allow http
sudo ufw allow https
sudo ufw allow ssh
do not forget this one- Proceed to port forwarding
- Run the Rails application with puma as usual to check if it works
Deployment and long server run
That’s the good two cents question as-of January 2019
Sources:
Mentionned: