Skip to main content

Amazon EC2

Virtual Servers in the Cloud

installing docker in ubuntu ec2 instance

apt-get update
apt-get install docker
sudo usermod -aG docker ubuntu
# log out of terminal and log back in
sudo systemctl start docker
docker run hello-world

Ubuntu | Docker Docs

AWS EC2 Instance Types

Deploy code to EC2

*/5 * * * * /home/ubuntu/deploy.sh

deploy.sh
#!/bin/bash

# Set the path to your Git repository
GIT_PATH="/home/ubuntu/repo"

# Change to the Git repository directory
cd $GIT_PATH

git fetch origin

NEW_COMMITS=$(git rev-list HEAD..origin/main)

# Check if there are any changes in the repository
if [ -n "$NEW_COMMITS" ]; then
# If there are changes, run the docker-compose command
git reset --hard origin/main
sudo docker compose -f docker-compose.prod.yaml up -d --no-deps --build web worker metabase
else
# If there are no changes, do nothing
echo "No changes in Git repository.

Amazon EC2 Auto Scaling Group (ASG)

Scale Compute Capacity to Meet Demand

Amazon EC2 Auto Scaling lifecycle hooks - Amazon EC2 Auto Scaling

EC2 > Networking > Elastic IP Addresses

An Elastic IP address is a static IPv4 address designed for dynamic cloud computing. An Elastic IP address is associated with your AWS account. With an Elastic IP address, you can mask the failure of an instance or software by rapidly remapping the address to another instance in your account.

An Elastic IP address is a public IPv4 address, which is reachable from the internet. If your instance does not have a public IPv4 address, you can associate an Elastic IP address with your instance to enable communication with the internet; for example, to connect to your instance from your local computer.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html

EC2 > Networking > ENI

An elastic network interface (referred to as anetwork interfacein this documentation) is a logical networking component in a VPC that represents a virtual network card.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html