- You must have AWS CLI configured (aws configure).
- Docker must be installed and running.
Amazon Linux 2023 uses dnf instead of yum. Run the following commands:
sudo dnf update -y
sudo dnf install -y dockerStart the Docker service:
sudo systemctl start dockerEnable it to start on boot:
sudo systemctl enable dockerAllow the ec2-user to run Docker commands without sudo:
sudo usermod -aG docker ec2-userThen either:
-
Reboot:
sudo reboot
-
Or log out and log back in for the group change to take effect.
Check Docker info:
docker infoYou should see both Client and Server info without errors.
Start it manually:
sudo systemctl start dockerCheck its status:
sudo systemctl status dockerIf it says active (running), everything is working correctly.
To ensure Docker starts automatically after a reboot:
sudo systemctl enable docker- Your IAM user/role must have permission to use ECR (like AmazonEC2ContainerRegistryFullAccess or similar).
- Navigate to IAM (Identity and Access Management) in your AWS Console.
- Go to Users → Click Create User.
- Set User Name as
ecs-docker. - Click Next → Select Set Permissions → Permission Options.
- Choose Attach Policies Directly → Search and select
AmazonEC2ContainerRegistryFullAccess. - Click Next → Click Create User.
- Open the
ecs-dockeruser profile. - Go to Security Credentials → Access Key → Create Access Key.
- Choose Use Case → Select CLI.
- Confirm: "I understand the recommendation and want to proceed".
- Click Next → Create Access Key.
- Download the
.csvfile containing access credentials.
-
🖥️ Open VS Code Terminal:
aws configure
-
Enter your credentials:
aws_access_key_id = YOUR_ACCESS_KEY aws_secret_access_key = YOUR_SECRET_KEY region = us-east-1 output = table -
Verify the configuration:
aws configure list aws sts get-caller-identity
-
Clone the project repository:
cd ~/Downloads mkdir Fullstack-nodejs-ecs-fargate-deployment cd Fullstack-nodejs-ecs-fargate-deployment git clone https://github.com/arumullayaswanth/Fullstack-nodejs-ecs-fargate-deployment.git cd Fullstack-nodejs-ecs-fargate-deployment ls
Go to Fullstack-nodejs-ecs-fargate-deployment/client/src/pages /config.js and update your API base URL:
// const API_BASE_URL = "http://localhost:8800";
const API_BASE_URL = "http://aluru.site";
export default API_BASE_URL;
// const API_BASE_URL = process.env.REACT_APP_API_BASE_URL || "http://backend";
// export default API_BASE_URL;
// const API_BASE_URL = "REACT_APP_API_BASE_URL_PLACEHOLDER";- Go to the AWS Management Console
- In the search bar at the top, type: Elastic Container Registry
- Click on Elastic Container Registry
- Select Private registry
- Click on Private repositories
- Click Create repository
- Under General settings, enter the repository name:
backend - Click Create repository
- After creation, open the backend repository
- Click View push commands
You will now see the Docker commands required to authenticate, build, tag, and push your image.
-
Navigate to the backend directory:
cd backend/ -
Authenticate Docker with ECR:
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 421954350274.dkr.ecr.us-east-1.amazonaws.com -
Build the Docker image:
docker build -t backend . -
Tag the image:
docker tag backend:latest 421954350274.dkr.ecr.us-east-1.amazonaws.com/backend:latest
-
Push the image:
docker push 421954350274.dkr.ecr.us-east-1.amazonaws.com/backend:latest
- Go to the AWS Management Console
- In the search bar at the top, type: Elastic Container Registry
- Click on Elastic Container Registry
- Select Private registry
- Click on Private repositories
- Click Create repository
- Under General settings, enter the repository name:
frontend - Click Create repository
- After creation, open the frontend repository
- Click View push commands
You will now see the Docker commands required to authenticate, build, tag, and push your image.
-
Navigate to the frontend directory:
cd ../client/ -
Authenticate Docker with ECR:
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 421954350274.dkr.ecr.us-east-1.amazonaws.com -
Build the Docker image:
docker build -t frontend . -
Tag the image:
docker tag frontend:latest 421954350274.dkr.ecr.us-east-1.amazonaws.com/frontend:latest
-
Push the image:
docker push 421954350274.dkr.ecr.us-east-1.amazonaws.com/frontend:latest
- Go to AWS Console → Amazon Elastic Container Registry.
- Select backend repository → Copy the image URI.
- Select frontend repository → Copy the image URI.
-
Go to VS Code → Open
terraform-ecs-fargate-fullstack-app→ Openbackend-task-server.tf -
Update your image in the
container_definitionsblock:container_definitions = jsonencode([ { name = "backend" image = "421954350274.dkr.ecr.us-east-1.amazonaws.com/backend:latest" # Replace with your backend image cpu = 256 memory = 512 essential = true } ])
-
Go to VS Code → Open
terraform-ecs-fargate-fullstack-app→ Openfrontend-task-server.tf -
Update your image in the
container_definitionsblock:container_definitions = jsonencode([ { name = "frontend" image = "421954350274.dkr.ecr.us-east-1.amazonaws.com/frontend:latest" # Replace with your frontend image cpu = 256 memory = 512 essential = true } ])
✅ Now your ECS Task Definitions are configured to use the latest images from Amazon ECR!
- Open VS Code Terminal and run:
llcd terraform-ecs-fargate-fullstack-app/ls
cd vpa-networklsterraform initterraform validateterraform planterraform apply --auto-approve
terraform show
terraform state listterraform apply --auto-approveterraform showterraform state list- Navigate to RDS Directory:
cd ..lscd rdsterraform initterraform validateterraform planterraform apply --auto-approve
terraform show
terraform state listterraform apply --auto-approveterraform showterraform state listmy challenge is my database created a new database now I am going to create insider database some existing records.
whenever i access a frontend and existing records you can see first then you can add your record in this case database inside you need to run some script to create existing data but the database if you want to connect extremal by using workbench and my database is private here.
in this case same network i am going to create one ec2 instance to connect rds and insert data
-
Launch EC2 Instance:
- Go to EC2 → Launch Instance
- Name:
bastion - AMI: Amazon Linux
- Keypair: Your selected key
- VPC:
ecs-vpc - Subnet:
ecs-public1 - Security Group:
terraform-98765432 - Launch
-
Connect and Configure EC2:
sudo -i
sudo yum install git -y
sudo yum install docker -y
sudo usermod -aG docker ec2-user
newgrp docker
sudo systemctl start docker
sudo systemctl status docker
sudo systemctl enable docker
sudo chmod 777 /var/run/docker.sock
yum install mariadb105-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
git clone https://github.com/arumullayaswanth/Fullstack-nodejs-ecs-fargate-deployment.git
cd backend/
mysql -h <your-rds-endpoint> -u admin -p < test.sql
(eg: mysql -h book-rds.c0n8k0a0swtz.us-east-1.rds.amazonaws.com -u admin -Yaswanth123reddy < test.sql)- SHOW DATABASES;
- USE test;
- SHOW TABLES;
- EXIT;
- Backend Task Update (
backend-task-server.tf):
Come back to VS code then change the ecs-task directory. And add rds endpoint near the db
environment = [
{ name = "DB_HOST", value = "book-rds.c0n8k0a0swtz.us-east-1.rds.amazonaws.com" }, // replace your databasw end point
{ name = "PORT", value = "3306" },
{ name = "DB_USERNAME", value = "admin" },
{ name = "DB_PASSWORD", value = "Yaswanth123reddy" }
]
cd ..lscd ecs-taskterraform initterraform validateterraform planterraform apply --auto-approve
terraform show
terraform state listterraform apply --auto-approveterraform showterraform state list-
Create Hosted Zone:
- Domain:
aluru.site - Type: Public Hosted Zone
- Domain:
-
Update Hostinger Nameservers:
- Paste the 4 NS records from Route 53:
- ns-865.awsdns-84.net
- ns-1995.awsdns-97.co.uk
- ns-1418.awsdns-59.org
- ns-265.awsdns-73.com
- Paste the 4 NS records from Route 53:
-
Create A Record in Route 53:
- Type: A - IPv4 address
- Alias: Yes
- Alias target: Choose Application and Classic Load Balancer
- Region: US East (N. Virginia)
- Alias target value: dualstack.backend-1016048026.us-east-1.elb.amazonaws.com (replace you backend load balances)
- Click Create record
Path: AWS Certificate Manager → Request Certificat
- Select: Request a public certificate
- Click Next
- Fully qualified domain name: aluru.site
- Validation method: DNS validation (recommended)
- Click Request
*** Step 7: Validate Domain in Route 53***
Path: AWS Certificate Manager → Certificates → Your Certificate ID
- Under domain, click Create DNS record in Amazon Route 53
- Select your hosted zone: aluru.site
- Click Create record
- Wait a few minutes for validation to complete
- Go to EC2 → Load Balancers → frontend-alb → Listeners.
- Add:
- Protocol: HTTPS
- Port: 443
- Action: Forward to web target group
- Security policy: ELBSecurityPolicy-2021-06 (or latest)
- Select ACM Certificate : Select the one for aluru.site
- Click Add
go to Google and search this website http://aluru.site and access the application now
Visit: http://aluru.site
terraform destroy -auto-approve