{"id":18573150,"url":"https://github.com/localstack-samples/sample-cdk-ecs-elb","last_synced_at":"2025-04-10T07:31:49.731Z","repository":{"id":199563249,"uuid":"700727374","full_name":"localstack-samples/sample-cdk-ecs-elb","owner":"localstack-samples","description":"A nodejs sample application that creates ecs tasks and attaches a load balancer to it","archived":false,"fork":false,"pushed_at":"2024-07-10T11:58:44.000Z","size":739,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-03-24T18:06:26.911Z","etag":null,"topics":["cdk","docker","ecr","ecs","elb","nodejs","remote-debug"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/localstack-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-05T07:13:00.000Z","updated_at":"2024-11-20T12:02:06.000Z","dependencies_parsed_at":"2024-07-10T13:13:02.452Z","dependency_job_id":"134ae827-3d41-438d-8272-3bfdf2759081","html_url":"https://github.com/localstack-samples/sample-cdk-ecs-elb","commit_stats":null,"previous_names":["localstack-samples/sample-cdk-ecs-elb"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-cdk-ecs-elb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-cdk-ecs-elb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-cdk-ecs-elb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-cdk-ecs-elb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/localstack-samples","download_url":"https://codeload.github.com/localstack-samples/sample-cdk-ecs-elb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248176386,"owners_count":21060058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cdk","docker","ecr","ecs","elb","nodejs","remote-debug"],"created_at":"2024-11-06T23:08:10.161Z","updated_at":"2025-04-10T07:31:49.339Z","avatar_url":"https://github.com/localstack-samples.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"### 🌐 Overview\n\nThe sample application, utilizing the AWS Cloud Development Kit (AWS CDK) 🛠️, orchestrates the deployment of a\ncontainerized application 📦 on AWS Fargate within an Amazon ECS (Elastic Container Service) cluster. The CDK\ninfrastructure-as-code model allows developers to define cloud resources using familiar programming languages 🖥️.\n\n![Solution](./docs/img/solution-diags.drawio.png \"Solution\")\n\n### 🔑 Key Components\n\n- **🌍 VPC and Cluster:**\n  The script initiates a new Virtual Private Cloud (VPC) and an ECS Cluster, ensuring a secure 🔐 and isolated network\n  environment and a logical grouping of ECS tasks and services, respectively.\n\n- **🐳 Docker Image Asset:**\n  The `DockerImageAsset` class is used to build a Docker image from a local directory (specified path) and push it to\n  Amazon Elastic Container Registry (ECR). The built image is then used in the ECS task definition.\n\n- **🚀 Task Definition and Container Definition:**\n  An ECS task definition is created, specifying the Docker image to use, CPU 🖥️, and memory requirements, network mode,\n  and logging configuration. A container within this task is defined, specifying port mappings and essential status.\n\n- **🛳️ ECS Fargate Service:**\n  The ECS service is configured to run on Fargate, which allows running containers without managing the underlying\n  instances. The service is configured with the above task definition, desired count of tasks, and a circuit breaker for\n  handling failures.\n\n- **⚖️ Application Load Balancer (ALB):**\n  An ALB is provisioned to distribute incoming HTTP/S traffic across multiple targets, such as ECS tasks, in multiple\n  Availability Zones. A listener is added to the load balancer to check for connection requests from clients, using the\n  HTTP protocol and listening on port 80.\n\n- **🎯 Target Group and Health Checks:**\n  Targets (in this case, the ECS service) are registered with a target group, which the ALB uses to route traffic to.\n  Health check settings ensure that traffic is routed only to healthy targets.\n\n## Getting Started 🏁\n\nThis guide assumes that you have cloned the repository and are in the project root directory. The following steps will\nguide you through the process of building, deploying, and running the sample application both locally and on AWS. We\nhave a [sample application](https://github.com/localstack-samples/sample-cdk-ecs-elb/tree/main/src) that listens on\nport `3000` and returns a JSON response.\n\n### Prerequisites 🧰\n\n- [Localstack Pro](https://localstack.cloud/pricing/)\n- [Docker](https://docs.docker.com/get-docker/)\n- [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html#getting_started_install)\n- [Node.js](https://nodejs.org/en/download/)\n- [cdklocal](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/)\n- [jq](https://jqlang.github.io/jq/download/)\n\n### Install Dependencies 📦\n\nInstall the project dependencies using the following command:\n\n```bash\nmake install\n```\n\n## Deploying the Application on Localstack ☁️\n\n### Step 1: Start LocalStack 🚦\n\nStart the LocalStack server using the following command:\n\n```bash\nexport LOCALSTACK_AUTH_TOKEN=\u003cYOUR_AUTH_TOKEN\u003e\nmake start-localstack\n```\n\n### Step 2: Deploy the Application 🚢\n\nDeploy your application locally using the following command:\n\n```bash\nmake deploy-local\n```\n\nThis command will deploy your application to the LocalStack. Ensure that there are no errors.\n\n### Step 3: Run Test Cases 🧪\n\nRun the application test cases using the following command:\n\n```bash\nmake test-local\n```\n\nEnsure that all test cases pass and pay attention to any output that is displayed. This step should validate that the\napplication is functioning as expected.\n\nAlternatively, you can also check the application by curling the ALB endpoint. You can find the ALB endpoint in the\nLocalStack console or by running the following command:\n\n```bash\nawslocal elbv2 describe-load-balancers --query 'LoadBalancers[0].DNSName'\n```\n\nNow you can curl the endpoint using the following command:\n\n```bash\nmake curl-local\n```\n\nThe output should be similar to the following:\n\n```bash\n{\"message\":\"Hello, Welcome to Localstack!\"}\n```\n\n### Step 4: Clean Up 🧹\n\nTo delete the application from LocalStack, run the following command:\n\n```bash\nmake destroy-local\n```\n\n## Deploying the Application on AWS ☁️\n\n### Step 1: Deploy the Application 🚢\n\nDeploy your application to AWS using the following command:\n\n```bash\nmake deploy\n```\n\nThis command will deploy your application to AWS. Ensure that there are no errors.\n\n### Step 2: Run Test Cases Against AWS🧪\n\nRun the application test cases using the following command:\n\n```bash\nmake test\n```\n\nAlternatively, you can also check the application by curling the ALB endpoint. You can find the ALB endpoint in the AWS\nconsole or by running the following command:\n\n```bash\nmake curl-aws\n```\n\nThe output should be similar to the following:\n\n```bash\n{\"message\":\"Hello, Welcome to Localstack!\"}\n```\n\n## 🧹 Cleaning Up\n\nTo delete the application from AWS, run the following command:\n\n```bash\nmake destroy\n```\n\n## 🚀 Configuring Visual Studio Code for Efficient Remote Node.js Debugging\n\nSetting up Visual Studio Code for remote Node.js debugging enables smoother and more intuitive development workflows.\nThis guide will walk you through the essential steps to configure your VSCode efficiently for remote debugging of your\nNode.js applications. 🛠️🔍\n\n1️⃣ **Configure LocalStack for remote Node.js debugging** 🛠️\n\nFirst, we need to configure LocalStack to enable remote debugging of Node.js applications. In devops-tooling/docker-compose.yml file, uncomment **ECS_DOCKER_FLAGS** line to enable required configuration for remote debugging. \n\n\n2️⃣ **Adding a Task to Wait for Remote Debugger Server** 🕰️\n\nFirst, let's ensure that VSCode waits for the remote debugger server to be available. Add a new task by creating or\nmodifying the `.vscode/tasks.json` file in your project directory.\n\n   ```json\n   {\n  \"version\": \"2.0.0\",\n  \"tasks\": [\n    {\n      \"label\": \"Wait Remote Debugger Server\",\n      \"type\": \"shell\",\n      \"command\": \"while [[ -z $(docker ps | grep :9229) ]]; do sleep 1; done; sleep 1;\"\n    }\n  ]\n}\n   ```\n\n3️⃣ **Setting up Debugging Configuration** 🎛️\n\nNext, define how VSCode should connect to the remote Node.js application. Create a new `launch.json` file or modify an\nexisting one from the *Run and Debug* tab, then add the following configuration.\n\n   ```json\n   {\n  \"version\": \"0.2.0\",\n  \"configurations\": [\n    {\n      \"address\": \"127.0.0.1\",\n      \"localRoot\": \"${workspaceFolder}\",\n      \"name\": \"Attach to Remote Node.js\",\n      \"port\": 9229,\n      \"remoteRoot\": \"/app\",\n      \"request\": \"attach\",\n      \"type\": \"node\",\n      \"preLaunchTask\": \"Wait Remote Debugger Server\"\n    }\n  ]\n}\n   ```\n\n4️⃣ **Start LocalStack**\n\nStart the LocalStack server using the following command:\n\n```bash\nexport LOCALSTACK_AUTH_TOKEN=\u003cYOUR_AUTH_TOKEN\u003e\nmake start-localstack\n```\n\n5️⃣ **Running the Debugger** 🏃\n\nFinally, run the debugger by selecting the *Attach to Remote Node.js* configuration from the *Run and Debug* tab. You\ncan now set breakpoints and debug your Node.js application running in a Docker container. 🐳\n\n## 📚 Resources 📚\n\n- [LocalStack CLI Documentation](https://docs.localstack.cloud/getting-started/installation/)\n- [LocalStack API Documentation](https://docs.localstack.cloud/user-guide/aws/feature-coverage/)\n- [Localstack CDK Documentation](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/)\n- [AWS CDK Documentation](https://docs.aws.amazon.com/cdk/latest/guide/home.html)\n- [AWS CLI Documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalstack-samples%2Fsample-cdk-ecs-elb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocalstack-samples%2Fsample-cdk-ecs-elb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalstack-samples%2Fsample-cdk-ecs-elb/lists"}