Tools: Step-by-Step Guide: Deploy a Containerized App to AWS

Tools: Step-by-Step Guide: Deploy a Containerized App to AWS

Source: Dev.to

1. Prepare the Application ## 2. Containerize the Application ## 3. Create an Amazon ECR Repository ## 4. Provision Infrastructure with Terraform ## 5. Verify the Application ## 6. Push the Project to GitHub ## 7. Add GitHub Actions for CI/CD ## 8. Add AWS Credentials to GitHub ## 9. Trigger Deployment ## Final Result ## Other Helpful Resources This guide explains the steps I followed to containerize an application and deploy it to AWS using Docker, Terraform, ECS Fargate, and GitHub Actions. The goal is simple. Build the app, package it in Docker, store the image in ECR, run it on ECS Fargate, and automate the deployment with GitHub Actions. Create a simple Node.js application. Example project structure: Install dependencies: Run the application locally to confirm it works. Run the container locally: ECR → Create repository After creating the repository, push your Docker image. Create infrastructure using Terraform. Resources created include: Initialize Terraform: Apply infrastructure: Confirm the ECS service is running. Once the ECS task is running, the application can be accessed using the public IP assigned to the service. Open the IP address in the browser to confirm the application is working. Create a repository on GitHub. Create this folder in your repository: In your GitHub repository, go to: Settings → Secrets → Actions These allow GitHub Actions to deploy to AWS. Push a change to the repository: GitHub Actions will start the pipeline. Your application will be redeployed automatically. This setup removes manual deployment and keeps the application updated whenever code changes. If you found this article helpful, share it with others who may find it interesting. How to Deploy a Kubernetes App on AWS EKS The Best AWS Services to Deploy Front-End Applications in 2025 What is Backend as a Service (BaaS)? A Beginner's Guide The Hidden Challenges of Building with AWS How to Create a CI/CD Pipeline Using AWS Elastic Beanstalk Stay updated with my projects by following me on Twitter, LinkedIn, and GitHub. Thank you for reading Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse CODE_BLOCK: app/ server.js package.json Dockerfile terraform/ Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: app/ server.js package.json Dockerfile terraform/ CODE_BLOCK: app/ server.js package.json Dockerfile terraform/ COMMAND_BLOCK: npm install Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: npm install COMMAND_BLOCK: npm install CODE_BLOCK: node server.js Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: node server.js CODE_BLOCK: node server.js CODE_BLOCK: http://localhost:3000 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: http://localhost:3000 CODE_BLOCK: http://localhost:3000 CODE_BLOCK: FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm install --production COPY . . EXPOSE 3000 CMD ["node", "app/server.js"] Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm install --production COPY . . EXPOSE 3000 CMD ["node", "app/server.js"] CODE_BLOCK: FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm install --production COPY . . EXPOSE 3000 CMD ["node", "app/server.js"] COMMAND_BLOCK: docker build -t job-tracker-app . Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: docker build -t job-tracker-app . COMMAND_BLOCK: docker build -t job-tracker-app . COMMAND_BLOCK: docker run -p 3000:3000 job-tracker-app Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: docker run -p 3000:3000 job-tracker-app COMMAND_BLOCK: docker run -p 3000:3000 job-tracker-app CODE_BLOCK: http://localhost:3000 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: http://localhost:3000 CODE_BLOCK: http://localhost:3000 CODE_BLOCK: job-tracker-app Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: job-tracker-app CODE_BLOCK: job-tracker-app CODE_BLOCK: aws ecr get-login-password --region us-east-1 \ | docker login --username AWS --password-stdin ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: aws ecr get-login-password --region us-east-1 \ | docker login --username AWS --password-stdin ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com CODE_BLOCK: aws ecr get-login-password --region us-east-1 \ | docker login --username AWS --password-stdin ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com COMMAND_BLOCK: docker tag job-tracker-app:latest ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/job-tracker-app:latest Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: docker tag job-tracker-app:latest ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/job-tracker-app:latest COMMAND_BLOCK: docker tag job-tracker-app:latest ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/job-tracker-app:latest COMMAND_BLOCK: docker push ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/job-tracker-app:latest Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: docker push ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/job-tracker-app:latest COMMAND_BLOCK: docker push ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/job-tracker-app:latest CODE_BLOCK: terraform init Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: terraform init CODE_BLOCK: terraform init CODE_BLOCK: terraform apply Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: terraform apply CODE_BLOCK: terraform apply CODE_BLOCK: 1/1 tasks running Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: 1/1 tasks running CODE_BLOCK: 1/1 tasks running COMMAND_BLOCK: git init git add . git commit -m "Initial commit" Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: git init git add . git commit -m "Initial commit" COMMAND_BLOCK: git init git add . git commit -m "Initial commit" COMMAND_BLOCK: git remote add origin YOUR_REPO_URL git branch -M main git push -u origin main Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: git remote add origin YOUR_REPO_URL git branch -M main git push -u origin main COMMAND_BLOCK: git remote add origin YOUR_REPO_URL git branch -M main git push -u origin main CODE_BLOCK: .github/workflows Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: .github/workflows CODE_BLOCK: .github/workflows CODE_BLOCK: deploy.yml Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY CODE_BLOCK: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY COMMAND_BLOCK: git push Enter fullscreen mode Exit fullscreen mode - Public subnets - Security groups - ECS cluster - ECS service - Application Load Balancer - build the Docker image - push the image to ECR - update the ECS service - build the Docker image - push it to ECR - update the ECS service - A containerized application. - Infrastructure created with Terraform. - Containers running on ECS Fargate. - Automated deployment using GitHub Actions. - How to Deploy a Kubernetes App on AWS EKS - The Best AWS Services to Deploy Front-End Applications in 2025 - What is Backend as a Service (BaaS)? A Beginner's Guide - The Hidden Challenges of Building with AWS - Play with Kubernetes - Docker 101 Tutorial - How to Create a CI/CD Pipeline Using AWS Elastic Beanstalk