ECR and ECS Configuration

Follow step-by-step instructions to prepare the infrastructure for Amazon ECR and ECS.

Amazon ECS is a fully managed container orchestration service that simplifies the deployment and scaling of containerized applications. Deploying a NestJS application to ECS is crucial for making our application resilient and scalable.

Previously, we’ve Dockerized our NestJS app and built a Docker image. In this lesson, we’ll create an ECR repository and push our Docker image into the ECR repository. We’ll also set up the required IAM role and create an ECS cluster to prepare the infrastructure for deploying ECS services in the later lesson.

Prerequisites

Before we start, let’s verify a couple prerequisites.

  • Ensure that the AWS MySQL database instance is running, the AddressBook database is created, and the database migration is executed successfully, as described in the previous lesson.

  • Ensure that we’ve obtained both the AWS access key and secret key and that we’ve entered them into the terminal environment variables in the previous lesson.

Create an ECR

Amazon ECR is a fully managed container registry service provided by AWS. It’s used for storing, managing, and deploying Docker container images. An AWS account possesses a registry, and each registry contains multiple repositories. Within each repository, multiple images can be stored.

ECR functions comparably to Docker Hub. Once we push our Docker image to ECR, it becomes available for utilization with various AWS services, including ECS. By default, an ECR repository is private. Only users with the necessary permissions can access and pull images from the repository. Pushing a Docker image to ECR is not publicly accessible unless we explicitly grant permission to specific AWS IAM users, roles, or other AWS accounts.

Click the “Run” button below to show the terminal. Then, run the following command to build the docker image for deployment:

Get hands-on with 1400+ tech skills courses.