DEV Community

Cover image for Deploying an App With AWS App Runner
Ijay
Ijay

Posted on

Deploying an App With AWS App Runner

Deploying applications can be a hassle, especially when managing servers and infrastructure. That's where AWS App Runner comes in! In this article, I'll walk you through how I deployed my Pantry Tracker App using Docker and AWS App Runner, making the entire process seamless.

Prerequisites

Why Use AWS App Runner?

AWS App Runner is a fully managed service that makes it easy to deploy containerized applications without worrying about server management. Here’s why I chose it:

  • Infrastructure management: No need to provision or maintain servers.

  • Scalability: It automatically scales based on demand.

  • Fast deployment: Just push your container image, and App Runner takes care of the rest.

  • Load Balancing: Built-in load balancing handles traffic efficiently without extra configurations.

Why Dockerize Your App?

Before deploying, I Dockerized my Next.js-based Pantry Tracker App. Why?

  • Portability: Works the same in any environment.

  • Consistency: Avoids the "works on my machine" problem.

  • Easy deployment: Package the app with its dependencies in one container.

Dockerize the App

Setting Up the Project

Technologies Used

  • Frontend: Next.js, React, Tailwind CSS.

  • Backend: Firebase (Firestore for database).

  • Deployment: AWS App Runner, AWS Elastic Container Registry (for container image repository), Docker.

Before starting, make sure you have:

Clone the Repository

git clone https://github.com/ijayhub/pantry-tracker-app.git
cd pantry-tracker-app
Enter fullscreen mode Exit fullscreen mode

Install Dependencies

npm install
Enter fullscreen mode Exit fullscreen mode

Run the Application Locally

npm start
Enter fullscreen mode Exit fullscreen mode

The app will be available at http://localhost:3000/.

Docker Setup

To containerize the application for deployment:

Create a Dockerfile

FROM node:18-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "run", "start"]
Enter fullscreen mode Exit fullscreen mode

Build and Run the Docker Container

docker build -t pantry-tracker-app .
docker run -p 3000:3000 pantry-tracker-app
Enter fullscreen mode Exit fullscreen mode

1. Push Docker Image to AWS Elastic Container Registry (ECR)

AWS App Runner pulls images from ECR, so we need to push our Docker image there.

Push Docker Image to AWS Elastic Container Registry (ECR)

aws ecr create-repository --repository-name pantry-tracker-app
aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <aws-account-id>.dkr.ecr.<your-region>.amazonaws.com
docker tag pantry-tracker-app:latest <aws-account-id>.dkr.ecr.<your-region>.amazonaws.com/pantry-tracker-app:latest
docker push <aws-account-id>.dkr.ecr.<your-region>.amazonaws.com/pantry-tracker-app:latest
Enter fullscreen mode Exit fullscreen mode

2. Deploy to AWS App Runner

  • Go to the AWS App Runner Console.

  • Create a new service and select Container Registry.

  • Choose your ECR repository and select the latest image.

  • Configure environment variables and deployment settings.

  • Click Deploy and let App Runner handle the rest!

Deploy the service

The visual output

result

Conclusion

Using AWS App Runner, I deployed my Pantry Tracker App without managing servers or dealing with complex configurations. By Dockerizing the app, I ensured consistency and portability, making deployment smooth and hassle-free.

If you're looking for an easy way to deploy your applications, Docker + AWS App Runner is the way to go!

You can find the Git repository here: pantry-tracker-app

If you found this article helpful, share it with others who may find it interesting.

Stay updated with my projects by following me on Twitter, LinkedIn, and GitHub.

Thank you for reading.

Hot sauce if you're wrong - web dev trivia for staff engineers

Hot sauce if you're wrong · web dev trivia for staff engineers (Chris vs Jeremy, Leet Heat S1.E4)

  • Shipping Fast: Test your knowledge of deployment strategies and techniques
  • Authentication: Prove you know your OAuth from your JWT
  • CSS: Demonstrate your styling expertise under pressure
  • Acronyms: Decode the alphabet soup of web development
  • Accessibility: Show your commitment to building for everyone

Contestants must answer rapid-fire questions across the full stack of modern web development. Get it right, earn points. Get it wrong? The spice level goes up!

Watch Video 🌶️🔥

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

If you found this post helpful, please leave a ❤️ or a friendly comment below!

Okay