Skip to content

AWS Deployment

PROJECT ZERO edited this page Jan 18, 2025 · 1 revision

AWS Deployment

This document provides step-by-step instructions for deploying the application to AWS.

Prerequisites

Before you begin, ensure you have the following:

  • An AWS account
  • AWS CLI installed and configured
  • Docker installed

Step 1: Build the Docker Image

First, build the Docker image for the application.

docker build -t myapp:latest .

Step 2: Push the Docker Image to Amazon ECR

Create a repository in Amazon ECR and push the Docker image to it.

  1. Create a repository:
aws ecr create-repository --repository-name myapp
  1. Authenticate Docker to the Amazon ECR registry:
aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <your-account-id>.dkr.ecr.<your-region>.amazonaws.com
  1. Tag the Docker image:
docker tag myapp:latest <your-account-id>.dkr.ecr.<your-region>.amazonaws.com/myapp:latest
  1. Push the Docker image:
docker push <your-account-id>.dkr.ecr.<your-region>.amazonaws.com/myapp:latest

Step 3: Deploy the Application to Amazon ECS

Create a task definition and deploy the application to Amazon ECS.

  1. Create a task definition JSON file (task-definition.json):
{
  "family": "myapp",
  "networkMode": "awsvpc",
  "containerDefinitions": [
    {
      "name": "myapp",
      "image": "<your-account-id>.dkr.ecr.<your-region>.amazonaws.com/myapp:latest",
      "memory": 512,
      "cpu": 256,
      "essential": true,
      "portMappings": [
        {
          "containerPort": 80,
          "hostPort": 80
        }
      ]
    }
  ],
  "requiresCompatibilities": ["FARGATE"],
  "cpu": "256",
  "memory": "512"
}
  1. Register the task definition:
aws ecs register-task-definition --cli-input-json file://task-definition.json
  1. Create a cluster:
aws ecs create-cluster --cluster-name myapp-cluster
  1. Create a service:
aws ecs create-service --cluster myapp-cluster --service-name myapp-service --task-definition myapp --desired-count 1 --launch-type FARGATE --network-configuration "awsvpcConfiguration={subnets=[<your-subnet-id>],securityGroups=[<your-security-group-id>],assignPublicIp=ENABLED}"

Step 4: Verify the Deployment

Verify that the application is running by checking the ECS service and accessing the application URL.

  1. Check the ECS service status:
aws ecs describe-services --cluster myapp-cluster --services myapp-service
  1. Access the application URL:

Retrieve the public IP address of the ECS task and access the application in your web browser.

Conclusion

You have successfully deployed the application to AWS using Amazon ECS and Docker.

AWS Deployment

This document provides step-by-step instructions for deploying the application to AWS.

Prerequisites

Before you begin, ensure you have the following:

  • An AWS account
  • AWS CLI installed and configured
  • Docker installed

Step 1: Build the Docker Image

First, build the Docker image for the application.

docker build -t myapp:latest .

Step 2: Push the Docker Image to Amazon ECR

Create a repository in Amazon ECR and push the Docker image to it.

  1. Create a repository:
aws ecr create-repository --repository-name myapp
  1. Authenticate Docker to the Amazon ECR registry:
aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <your-account-id>.dkr.ecr.<your-region>.amazonaws.com
  1. Tag the Docker image:
docker tag myapp:latest <your-account-id>.dkr.ecr.<your-region>.amazonaws.com/myapp:latest
  1. Push the Docker image:
docker push <your-account-id>.dkr.ecr.<your-region>.amazonaws.com/myapp:latest

Step 3: Deploy the Application to Amazon ECS

Create a task definition and deploy the application to Amazon ECS.

  1. Create a task definition JSON file (task-definition.json):
{
  "family": "myapp",
  "networkMode": "awsvpc",
  "containerDefinitions": [
    {
      "name": "myapp",
      "image": "<your-account-id>.dkr.ecr.<your-region>.amazonaws.com/myapp:latest",
      "memory": 512,
      "cpu": 256,
      "essential": true,
      "portMappings": [
        {
          "containerPort": 80,
          "hostPort": 80
        }
      ]
    }
  ],
  "requiresCompatibilities": ["FARGATE"],
  "cpu": "256",
  "memory": "512"
}
  1. Register the task definition:
aws ecs register-task-definition --cli-input-json file://task-definition.json

aws ecs create-service --cluster myapp-cluster --service-name myapp-service --task-definition myapp --desired-count 1 --launch-type FARGATE --network-configuration "awsvpcConfiguration={subnets=[],securityGroups=[],assignPublicIp=ENABLED}"


## Step 4: Verify the Deployment

Verify that the application is running by checking the ECS service and accessing the application URL.

1. Check the ECS service status:

```sh
aws ecs describe-services --cluster myapp-cluster --services myapp-service
  1. Access the application URL:

Retrieve the public IP address of the ECS task and access the application in your web browser.

Conclusion

You have successfully deployed the application to AWS using Amazon ECS and Docker.

TABLE OF CONTENTS

Clone this wiki locally