- Set up an Amazon AWS account
- Create ECR repositories for both backend and frontend
- Clone the following repositories into your local machine:
git clone https://github.com/turingplanet/unified-api-docker.git git clone https://github.com/turingplanet/react-frontend-docker.git git clone https://github.com/turingplanet/cloud-deployment.git - Install Terraform
-
Generate an SSH key pair under the terraform folder path by running:
ssh-keygen -t rsa -b 2048 -f ./id_rsa -
Navigate to the terraform directory and run the following commands:
terraform init terraform applyThis will initialize the Terraform working directory and then create or update your infrastructure, including deploying your EC2 instance.
-
Once the EC2 instance is launched, SSH into it:
ssh -i id_rsa ec2-user@<your_ec2_ip_address> -
Copy the content of ec2_build.sh to your EC2 instance and edit it to configure AWS and install Docker. Remember to replace the placeholder AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY with your own credentials in the script. Then execute the script.
chmod +x ec2_build.sh ./ec2_build.sh -
Set up Docker Compose by running:
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
-
In the build_and_push.sh file, replace AWS_REGION, AWS_ACCOUNT_ID, and ECR_REPOSITORY with your correct AWS settings.
-
Run build_and_push.sh locally to build the Docker image and push it to ECR. Before running the script, update the secret.yml file with your OpenAI API key.
-
Create a docker-compose.yml file in EC2 and copy the content from ec2-docker-compose.yml. Remember to replace the OPENAI_API_KEY value with your own OpenAI API key and update the image name to use your correct AWS account ID and ECR repository.
-
Pull your backend ECR repository and run Docker Compose:
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <your_aws_account_id>.dkr.ecr.us-east-1.amazonaws.com docker-compose up --pull always -d -
Run the upload_db_data.sh script locally to upload your MongoDB data to the EC2 instance.
- Replace IP_ADDRESS with the public IP address of your EC2 instance.
- Replace LOCAL_DUMP_PATH with the full path to your local MongoDB dump directory.
-
Test your API by accessing
http://<ec2_ip_address>:5001/api/news_sentiment?symbol=TSLA&sort_field=time_published&sort_order=descin your browser.
-
Replace API_BASE_URL in config.js with your EC2 instance's public IP address.
-
Build the frontend Docker image and push it to ECR locally using the build_and_push.sh script. Remember to replace AWS_REGION, AWS_ACCOUNT_ID, and ECR_REPOSITORY with your correct AWS settings in the script before running it.
-
Pull and run your frontend image from ECR:
docker pull <your_aws_account_id>.dkr.ecr.us-east-1.amazonaws.com/stock_platform_react_frontend:latest docker run -d -p 3000:3000 <your_aws_account_id>.dkr.ecr.us-east-1.amazonaws.com/stock_platform_react_frontend:latest -
Access your website by navigating to
http://<ec2_ip_address>:3000in your browser.