|
| 1 | +### 🌐 Overview |
| 2 | + |
| 3 | +The sample application, utilizing the AWS Cloud Development Kit (AWS CDK) 🛠️, orchestrates the deployment of a containerized application 📦 on AWS Fargate within an Amazon ECS (Elastic Container Service) cluster. The CDK infrastructure-as-code model allows developers to define cloud resources using familiar programming languages 🖥️. |
| 4 | + |
| 5 | +### 🔑 Key Components |
| 6 | + |
| 7 | +- **🌍 VPC and Cluster:** |
| 8 | + The script initiates a new Virtual Private Cloud (VPC) and an ECS Cluster, ensuring a secure 🔐 and isolated network environment and a logical grouping of ECS tasks and services, respectively. |
| 9 | + |
| 10 | +- **🐳 Docker Image Asset:** |
| 11 | + The `DockerImageAsset` class is used to build a Docker image from a local directory (specified path) and push it to Amazon Elastic Container Registry (ECR). The built image is then used in the ECS task definition. |
| 12 | + |
| 13 | +- **🚀 Task Definition and Container Definition:** |
| 14 | + An ECS task definition is created, specifying the Docker image to use, CPU 🖥️, and memory requirements, network mode, and logging configuration. A container within this task is defined, specifying port mappings and essential status. |
| 15 | + |
| 16 | +- **🛳️ ECS Fargate Service:** |
| 17 | + The ECS service is configured to run on Fargate, which allows running containers without managing the underlying instances. The service is configured with the above task definition, desired count of tasks, and a circuit breaker for handling failures. |
| 18 | + |
| 19 | +- **⚖️ Application Load Balancer (ALB):** |
| 20 | + An ALB is provisioned to distribute incoming HTTP/S traffic across multiple targets, such as ECS tasks, in multiple Availability Zones. A listener is added to the load balancer to check for connection requests from clients, using the HTTP protocol and listening on port 80. |
| 21 | + |
| 22 | +- **🎯 Target Group and Health Checks:** |
| 23 | + Targets (in this case, the ECS service) are registered with a target group, which the ALB uses to route traffic to. Health check settings ensure that traffic is routed only to healthy targets. |
| 24 | + |
| 25 | + ## Getting Started 🏁 |
| 26 | + |
| 27 | +This guide assumes that you have cloned the repository and are in the project root directory. The following steps will guide you through the process of building, deploying, and running the sample application both locally and on AWS. |
| 28 | + |
| 29 | +### Prerequisites 🧰 |
| 30 | + |
| 31 | +- [Localstack Pro](https://localstack.cloud/pricing/) |
| 32 | +- [Docker](https://docs.docker.com/get-docker/) |
| 33 | +- [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html#getting_started_install) |
| 34 | +- [Node.js](https://nodejs.org/en/download/) |
| 35 | +- [cdklocal](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/) |
| 36 | + |
| 37 | + |
| 38 | +### Install Dependencies 📦 |
| 39 | + |
| 40 | +Install the project dependencies using the following command: |
| 41 | + |
| 42 | +```bash |
| 43 | +make install |
| 44 | +``` |
| 45 | + |
| 46 | +## Deploying the Application on Localstack ☁️ |
| 47 | + |
| 48 | +### Step 1: Start LocalStack 🚦 |
| 49 | + |
| 50 | +Start the LocalStack server using the following command: |
| 51 | + |
| 52 | +```bash |
| 53 | +export LOCALSTACK_API_KEY=<YOUR_API_KEY> |
| 54 | +DEBUG=1 localstack start |
| 55 | +``` |
| 56 | + |
| 57 | +We specified `DEBUG=1` to get the printed LocalStack logs directly in the terminal to help us visualize the background tasks in action. If you prefer running LocalStack in detached mode, you can add the `-d` flag to the `localstack start` command, and use Docker Desktop to view the logs. |
| 58 | + |
| 59 | +### Step 2: Deploy the Application 🚢 |
| 60 | + |
| 61 | +Deploy your application locally using the following command: |
| 62 | + |
| 63 | +```bash |
| 64 | +make deploy-local |
| 65 | +``` |
| 66 | + |
| 67 | +This command will deploy your application to the LocalStack. Ensure that there are no errors. |
| 68 | + |
| 69 | +### Step 3: Run Test Cases 🧪 |
| 70 | + |
| 71 | +Run the application test cases using the following command: |
| 72 | + |
| 73 | +```bash |
| 74 | +make test |
| 75 | +``` |
| 76 | + |
| 77 | +Ensure that all test cases pass and pay attention to any output that is displayed. This step should validate that the application is functioning as expected. |
| 78 | + |
| 79 | +## Deploying the Application on AWS ☁️ |
| 80 | + |
| 81 | +### Step 1: Deploy the Application 🚢 |
| 82 | + |
| 83 | +Deploy your application to AWS using the following command: |
| 84 | + |
| 85 | +```bash |
| 86 | +make deploy |
| 87 | +``` |
| 88 | + |
| 89 | +This command will deploy your application to AWS. Ensure that there are no errors. |
| 90 | + |
| 91 | +### Step 2: Run Test Cases 🧪 |
| 92 | + |
| 93 | +Run the application test cases using the following command: |
| 94 | + |
| 95 | +```bash |
| 96 | +make test |
| 97 | +``` |
| 98 | + |
| 99 | +## 🚀 Configuring Visual Studio Code for Efficient Remote Node.js Debugging 🚀 |
| 100 | + |
| 101 | +Setting up Visual Studio Code for remote Node.js debugging enables smoother and more intuitive development workflows. This guide will walk you through the essential steps to configure your VSCode efficiently for remote debugging of your Node.js applications. 🛠️🔍 |
| 102 | + |
| 103 | +1️⃣ **Adding a Task to Wait for Remote Debugger Server** 🕰️ |
| 104 | + |
| 105 | + First, let's ensure that VSCode waits for the remote debugger server to be available. Add a new task by creating or modifying the `.vscode/tasks.json` file in your project directory. |
| 106 | + |
| 107 | + ```json |
| 108 | + { |
| 109 | + "version": "2.0.0", |
| 110 | + "tasks": [ |
| 111 | + { |
| 112 | + "label": "Wait Remote Debugger Server", |
| 113 | + "type": "shell", |
| 114 | + "command": "while [[ -z $(docker ps | grep :9229) ]]; do sleep 1; done; sleep 1;" |
| 115 | + } |
| 116 | + ] |
| 117 | + } |
| 118 | + ``` |
| 119 | + |
| 120 | +2️⃣ **Setting up Debugging Configuration** 🎛️ |
| 121 | + |
| 122 | + Next, define how VSCode should connect to the remote Node.js application. Create a new `launch.json` file or modify an existing one from the *Run and Debug* tab, then add the following configuration. |
| 123 | + |
| 124 | + ```json |
| 125 | + { |
| 126 | + "version": "0.2.0", |
| 127 | + "configurations": [ |
| 128 | + { |
| 129 | + "address": "127.0.0.1", |
| 130 | + "localRoot": "${workspaceFolder}", |
| 131 | + "name": "Attach to Remote Node.js", |
| 132 | + "port": 9229, |
| 133 | + "remoteRoot": "/var/task/", |
| 134 | + "request": "attach", |
| 135 | + "type": "node", |
| 136 | + "preLaunchTask": "Wait Remote Debugger Server" |
| 137 | + }, |
| 138 | + ] |
| 139 | + } |
| 140 | + ``` |
| 141 | + |
| 142 | +3️⃣ **Running the Debugger** 🏃 |
| 143 | + |
| 144 | + Finally, run the debugger by selecting the *Attach to Remote Node.js* configuration from the *Run and Debug* tab. You can now set breakpoints and debug your Node.js application running in a Docker container. 🐳 |
| 145 | + |
| 146 | +## 📚 Resources 📚 |
| 147 | + |
| 148 | +- [LocalStack CLI Documentation](https://docs.localstack.cloud/getting-started/installation/) |
| 149 | +- [LocalStack API Documentation](https://docs.localstack.cloud/user-guide/aws/feature-coverage/) |
| 150 | +- [Localstack CDK Documentation](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/) |
| 151 | +- [AWS CDK Documentation](https://docs.aws.amazon.com/cdk/latest/guide/home.html) |
| 152 | +- [AWS CLI Documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) |
0 commit comments