DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

Deploy a Developer's Application to AWS Using Docker, Amazon ECR, Amazon ECS, and Application Load Balancer

Objective

In this lab, you will act as a DevOps Engineer.

The developer (Jules) has already written the application and pushed the source code to GitHub.

Your responsibility is not to write the application.

Your responsibility is to package it, deploy it, and make it available to users.

By the end of this lab, you will:

  • Build a Docker image
  • Push the image to Amazon ECR
  • Deploy the container to Amazon ECS (Fargate)
  • Configure an Application Load Balancer
  • Access the application through the browser

Architecture

Developer
      │
      ▼
Application Source Code
      │
      ▼
Docker Image
      │
      ▼
Amazon ECR
      │
      ▼
Amazon ECS (Fargate)
      │
      ▼
Application Load Balancer
      │
      ▼
Users
Enter fullscreen mode Exit fullscreen mode

Scenario

Jules is a Software Developer.

He finished developing the application.

He informs the DevOps team:

"The application is ready. Please deploy it."

Now your work begins.


Step 1 – Open the Project

Open the project in VS Code.

Look at the project structure.

Example:

restaurant-app/

Dockerfile
package.json
src/
public/
README.md
Enter fullscreen mode Exit fullscreen mode

Why?

Before deploying an application, a DevOps engineer needs to understand the project structure.

You should identify:

  • Which programming language is used
  • Which package manager is used
  • Which port the application runs on
  • Whether a Dockerfile already exists

Step 2 – Verify the Application

Run the application locally.

Example:

npm install

npm start
Enter fullscreen mode Exit fullscreen mode

Open

http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

Verify the application works.


Why?

Never deploy an application you haven't tested.

If it doesn't work locally, it won't work in AWS.


Step 3 – Review the Dockerfile

Open the Dockerfile.

Example:

FROM node:20

WORKDIR /app

COPY package*.json .

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm","start"]
Enter fullscreen mode Exit fullscreen mode

Why?

Docker packages the application and all of its dependencies into a container.

This allows the application to run consistently on any machine.


Step 4 – Build the Docker Image

Run:

docker build -t restaurant-app:v1 .
Enter fullscreen mode Exit fullscreen mode

Verify:

docker images
Enter fullscreen mode Exit fullscreen mode

Expected output:

restaurant-app
v1
Enter fullscreen mode Exit fullscreen mode

Why?

A Docker image is a portable package containing:

  • Operating System
  • Runtime
  • Dependencies
  • Application Code

Amazon ECS runs Docker images, not source code.


Step 5 – Test the Docker Image

Run:

docker run -d -p 3000:3000 restaurant-app:v1
Enter fullscreen mode Exit fullscreen mode

Open

http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

Verify the application loads successfully.


Why?

Always test the Docker image before pushing it to AWS.

This prevents deployment failures later.


Step 6 – Create an Amazon ECR Repository

Open AWS Console.

Navigate to

Amazon ECR
Enter fullscreen mode Exit fullscreen mode

Click

Create Repository
Enter fullscreen mode Exit fullscreen mode

Repository Name

restaurant-app
Enter fullscreen mode Exit fullscreen mode

Click

Create
Enter fullscreen mode Exit fullscreen mode

Why?

Amazon ECR is a private Docker registry.

It stores Docker images.

Amazon ECS downloads images from Amazon ECR.


Step 7 – Authenticate Docker to Amazon ECR

Run:

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

Expected output:

Login Succeeded
Enter fullscreen mode Exit fullscreen mode

Why?

Docker must authenticate before pushing images into Amazon ECR.


Step 8 – Tag the Docker Image

Run:

docker tag restaurant-app:v1 ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/restaurant-app:v1
Enter fullscreen mode Exit fullscreen mode

Why?

Docker needs to know where the image will be stored.

Tagging associates the image with the ECR repository.


Step 9 – Push the Image

Run:

docker push ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/restaurant-app:v1
Enter fullscreen mode Exit fullscreen mode

Open Amazon ECR.

Verify the image appears.


Why?

Amazon ECS cannot deploy images stored only on your laptop.

The image must first be stored in Amazon ECR.


Step 10 – Create an Amazon ECS Cluster

Navigate to

Amazon ECS
Enter fullscreen mode Exit fullscreen mode

Click

Create Cluster
Enter fullscreen mode Exit fullscreen mode

Choose

Networking only (Fargate)
Enter fullscreen mode Exit fullscreen mode

Cluster Name

restaurant-cluster
Enter fullscreen mode Exit fullscreen mode

Create the cluster.


Why?

The cluster is the environment where containers run.

Using AWS Fargate means AWS manages the servers.

As a DevOps engineer, you don't need to install or patch operating systems.


Step 11 – Create a Task Definition

Create a new Task Definition.

Configure:

Launch Type:
Fargate
Enter fullscreen mode Exit fullscreen mode

Container Image

ECR Image URI
Enter fullscreen mode Exit fullscreen mode

CPU

0.5 vCPU
Enter fullscreen mode Exit fullscreen mode

Memory

1 GB
Enter fullscreen mode Exit fullscreen mode

Port

3000
Enter fullscreen mode Exit fullscreen mode

Save the Task Definition.


Why?

The Task Definition is the blueprint for running the container.

It tells ECS:

  • Which image to use
  • CPU allocation
  • Memory allocation
  • Port mapping

Step 12 – Create an ECS Service

Inside the cluster

Click

Create Service
Enter fullscreen mode Exit fullscreen mode

Select

Task Definition
Enter fullscreen mode Exit fullscreen mode

Desired Tasks

1
Enter fullscreen mode Exit fullscreen mode

Launch Type

Fargate
Enter fullscreen mode Exit fullscreen mode

Why?

A Task runs only once.

A Service continuously monitors the application.

If the container crashes, ECS automatically starts a new one.


Step 13 – Create an Application Load Balancer

Navigate to

EC2

Load Balancers
Enter fullscreen mode Exit fullscreen mode

Create

Application Load Balancer
Enter fullscreen mode Exit fullscreen mode

Configure:

Internet Facing

HTTP

Port 80


Why?

Containers have private IP addresses.

Users on the internet cannot access them directly.

The Application Load Balancer receives traffic from users and forwards requests to healthy ECS tasks.


Step 14 – Create a Target Group

Create a Target Group.

Type

IP
Enter fullscreen mode Exit fullscreen mode

Health Check Path

/
Enter fullscreen mode Exit fullscreen mode

Why?

The Target Group monitors the health of the application.

Only healthy containers receive traffic.


Step 15 – Connect ECS Service to the Load Balancer

Edit the ECS Service.

Attach

Application Load Balancer
Enter fullscreen mode Exit fullscreen mode

Select

Target Group
Enter fullscreen mode Exit fullscreen mode

Container Port

3000
Enter fullscreen mode Exit fullscreen mode

Deploy.


Why?

Without connecting ECS to the Load Balancer, users cannot reach the application.


Step 16 – Test the Application

Copy the ALB DNS name.

Example:

http://restaurant-alb-123456.us-east-1.elb.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

Open it in your browser.

Verify that the application loads successfully.


Lab Complete

Congratulations!

You have successfully completed the responsibilities of a DevOps Engineer:

  • ✅ Received application code from the developer
  • ✅ Built a Docker image
  • ✅ Tested the container locally
  • ✅ Created an Amazon ECR repository
  • ✅ Pushed the image to Amazon ECR
  • ✅ Created an Amazon ECS cluster
  • ✅ Created a Task Definition
  • ✅ Created an ECS Service
  • ✅ Created an Application Load Balancer
  • ✅ Deployed the application to AWS

Questions

  1. Why do we use Docker instead of deploying source code directly?
  2. What is the purpose of Amazon ECR?
  3. Why can't Amazon ECS run source code directly?
  4. What information is stored in an ECS Task Definition?
  5. What is the difference between an ECS Task and an ECS Service?
  6. Why do we need an Application Load Balancer?
  7. What happens if an ECS task becomes unhealthy?
  8. Why do we test the Docker container before pushing it to ECR?
  9. What would happen if the security group did not allow traffic from the ALB to ECS?
  10. In your own words, describe the complete deployment flow from the developer's code to the running application.

This is a beginner-friendly lab that closely reflects a real-world DevOps deployment workflow while keeping the scope focused on Docker → ECR → ECS → ALB before introducing CI/CD in later labs.

Top comments (0)