-
Notifications
You must be signed in to change notification settings - Fork 0
Deployment Setup
This guide walks through deploying the backend service on AWS using IAM, ECR, ECS, and Amplify. The deployment process ensures a secure, scalable, and containerized environment for the application.
Before we begin, ensure you have:
- An AWS account with administrative access.
- The AWS CLI installed and configured.
- Docker installed on your local machine.
- Your backend service containerized using Docker.
- Log in to your AWS account and navigate to the AWS IAM Console.
- In the left sidebar, click Users → Create User.
- Provide a username (e.g.,
backend-deploy-user). - Select Access Key - Programmatic Access.
Attach the following policies to grant the necessary permissions:
- AmazonEC2ContainerRegistryFullAccess – Allows full access to Amazon ECR (push, pull, delete images).
- AmazonECS_FullAccess – Provides full permissions to create and manage ECS resources.
- IAMFullAccess – Enables role and permission management.
- CloudWatchLogsFullAccess – Allows access to CloudWatch for ECS logging.
- AmazonS3ReadOnlyAccess – Grants read-only access to S3, useful if storing static assets or configuration.
- In the IAM user settings, navigate to Security Credentials.
- Scroll to the Access Keys section and click Create Access Key.
- Copy both the Access Key ID and Secret Access Key. Store these securely.
Run the following command and enter the IAM credentials when prompted:
aws configure- Open the Amazon ECR Console.
- Click Create Repository.
- Enter a repository name (e.g.,
backend-service). - Select Private Repository.
- Click Create and note the repository URI.
To push Docker images to ECR, first authenticate your local Docker client:
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.comEnsure you replace the following variables:
-
${AWS_REGION}with the AWS region (e.g.,us-east-2) -
${AWS_ACCOUNT_ID}with your AWS account ID.
Once the Amazon ECR repository is set up, we need to build, tag, and push the Docker image. This ensures that the backend service is properly containerized and stored in AWS Elastic Container Registry (ECR) for deployment.
We will use docker buildx to build the image. This ensures compatibility with AWS Fargate, which runs on linux/amd64 architecture.
docker buildx build \
--platform linux/amd64 \
--provenance=false \
-t ${ECR_REPOSITORY_NAME}:latest \
--load .-
--platform linux/amd64→ Ensures compatibility with AWS Fargate. -
--provenance=false→ Disables provenance metadata, reducing build time. -
-t ${ECR_REPOSITORY_NAME}:latest→ Tags the image locally as latest. -
--load→ Loads the built image into the local Docker daemon.
Tagging is required so the image can be correctly referenced when pushing to ECR.
docker tag ${ECR_REPOSITORY_NAME}:latest \
${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY_NAME}:latest•
docker buildx build \
--platform linux/amd64 \
--provenance=false \
-t ${ECR_REPOSITORY_NAME}:latest \
--load .docker tag ${ECR_REPOSITORY_NAME}:latest \
${AWS_ACCOUNT_ID}.dkr.ecr.us-east-2.amazonaws.com/${ECR_REPOSITORY_NAME}:latestdocker push ${AWS_ACCOUNT_ID}.dkr.ecr.us-east-2.amazonaws.com/${ECR_REPOSITORY_NAME}:latestpoetry add awscli aws-sam-clibrew install awscli- Go to AWS Console → AWS IAM Management Console
Navigate to:
- IAM (Identity and Access Management)
- In the left sidebar, click Users
- Create a new IAM User Assign the appropriate policies to IAM User:
- AWSLambdaFullAccess
- AmazonAPIGatewayAdministrator
- AmazonEC2ContainerRegistryFullAccess
- IAMFullAccess
- CloudWatchLogsFullAccess
Create a new access key
- Click Security credentials
- Scroll to Access keys
- Select "Create access key"
- Copy both the "Access Key ID" and "Secret Access Key" into the
.envfile
aws configureRun the following command to log in to AWS Elastic Container Registry (ECR):
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.comaws ecr create-repository \
--repository-name ${ECR_REPOSITORY_NAME} \
--region ${AWS_REGION}docker buildx build \
--platform linux/amd64 \
--provenance=false \
-t ${ECR_REPOSITORY_NAME}:latest \
--load .docker tag ${ECR_REPOSITORY_NAME}:latest \
${AWS_ACCOUNT_ID}.dkr.ecr.us-east-2.amazonaws.com/${ECR_REPOSITORY_NAME}:latestdocker push ${AWS_ACCOUNT_ID}.dkr.ecr.us-east-2.amazonaws.com/${ECR_REPOSITORY_NAME}:latestaws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 312093527157.dkr.ecr.us-east-2.amazonaws.compoetry add awscli aws-sam-cliInstall AWS CLI
brew install awscli