First create a virtual environment
Activate environment (Windows Powershell)
.\. venv\S cripts\A ctivate.ps1
pip install -r requirements
fastapi dev .\a pi\r un_api.py
ApprAIse (localhost)
Setting up Docker, AWS EC2 and ECR
Create an ECR on AWS Console
Go to "View push commands"
Keep tab open will need later.
Create an EC2 on AWS Console
Keep everything the same for Free Tier
Download *.pem key.
Open BASH terminal
chmod 400 *.pem
Connect to EC2 using SSH
Go to instance and check SSH command by clicking on "Connect"
Enter CMD into BASH terminal
Update instance
Install Docker
sudo yum install -y docker
Start Docker service
sudo service docker start
Add the ec2-user to the docker group
sudo usermod -a -G docker ec2-user
Reboot instance for above command to take effect
Use AWS console, "Instance State", "Reboot instance"
Connect to Instance again using SSH
Authenticate AWS CLI on local terminal
Download AWS CLI
Create an IAM User with proper permission (I just did the admin all one)
Go to tab "Security credentials"
Scroll down and click "Create access key"
Download access keys to CSV
Open ANOTHER BASH terminal
aws configure
Using the downloaded CSV enter credentials
Authenticate local Docker with your ECR
See step 1 for this command
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <YOUR ID>.dkr.ecr.us-east-1.amazonaws.com
Build local docker image
See step 1 for this command
docker build -t appraise .
Tag the image
See step 1 for this command
docker tag appraise:latest <YOUR ID>.dkr.ecr.us-east-1.amazonaws.com/appraise:latest
Push to ECR
See step 1 for this command
docker push <YOUR ID>.dkr.ecr.us-east-1.amazonaws.com/appraise:latest
Authenticate EC2 with AWS CLI credentials
Back to the BASH terminal with the Instance SHH
aws configure
Using the downloaded CSV enter credentials
Pull image from ECR
Reload the ECR tab and click on "latest"
Copy URI
Authenticate Docker in the Instance SSH
Back to the terminal with the Instance SSH
Get the <IMAGE_ID>
Go to your instance in the EC2 dashboard
click on it
go to the Security tab
click on your security group
click Edit inbound rules
add a new rule
select all traffic
add a new rule
port 80 with 0.0.0.0/0
add a new rule
port 433 with 0.0.0.0/0
Create Caddyfile
vim Caddyfile
type domain.com {reverse_proxy appraise:8000}
Run docker_reset.sh
Use this script on the EC2!
chmod +x docker_reset.sh
./docker_reset.sh
The script will prompt you for the <IMAGE_ID>
That's it! Unless you ran into error. I can't help with that.