Skip to content

Commit f9740da

Browse files
committed
initial commit
0 parents  commit f9740da

26 files changed

+12325
-0
lines changed

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"address": "127.0.0.1",
6+
"localRoot": "${workspaceFolder}",
7+
"name": "Attach to Remote Node.js",
8+
"port": 9229,
9+
"remoteRoot": "/var/task/",
10+
"request": "attach",
11+
"type": "node",
12+
"preLaunchTask": "Wait Remote Debugger Server"
13+
},
14+
]
15+
}

.vscode/tasks.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Wait Remote Debugger Server",
6+
"type": "shell",
7+
"command": "while [[ -z $(docker ps | grep :9229) ]]; do sleep 1; done; sleep 1;"
8+
}
9+
]
10+
}

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CDIR = cd iac/awscdk
2+
3+
usage: ## Show this help in table format
4+
@echo "| Target | Description |"
5+
@echo "|------------------------|-------------------------------------------------------------------|"
6+
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/:.*##\s*/##/g' | awk -F'##' '{ printf "| %-22s | %-65s |\n", $$1, $$2 }'
7+
8+
9+
deploy: ## Bootstrap and deploy the CDK app to AWS
10+
${CDIR}; cdk bootstrap; cdk deploy --outputs-file ./ouput.json --json
11+
12+
destroy: ## Destroy the deployed CDK stack in AWS
13+
${CDIR}; cdk destroy
14+
15+
destroy-local: ## Destroy the deployed CDK stack locally
16+
${CDIR}; cdklocal destroy
17+
18+
deploy-local: ## Bootstrap and deploy the CDK app locally
19+
${CDIR}; cdklocal bootstrap && \
20+
cdklocal deploy --outputs-file ./ouput.json --json --require-approval never
21+
22+
test: ## Run integration tests
23+
npm run test
24+
25+
install: ## Install npm dependencies
26+
${CDIR}; npm install
27+
28+
.PHONY: usage install test deploy destroy deploy-local destroy-local bootstrap-local

README.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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)

iac/awscdk/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
3+
# CDK asset staging directory
4+
.cdk.staging
5+
cdk.out
6+
7+
.vscode

iac/awscdk/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# CDK asset staging directory
2+
.cdk.staging
3+
cdk.out

iac/awscdk/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Welcome to your CDK JavaScript project
2+
3+
This is a blank project for CDK development with JavaScript.
4+
5+
The `cdk.json` file tells the CDK Toolkit how to execute your app. The build step is not required when using JavaScript.
6+
7+
## Useful commands
8+
9+
* `npm run test` perform the jest unit tests
10+
* `cdk deploy` deploy this stack to your default AWS account/region
11+
* `cdk diff` compare deployed stack with current state
12+
* `cdk synth` emits the synthesized CloudFormation template

iac/awscdk/bin/repo.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
3+
const cdk = require('aws-cdk-lib');
4+
const { RepoStack } = require('../lib/repo-stack');
5+
6+
const app = new cdk.App();
7+
new RepoStack(app, 'RepoStack', {
8+
/* If you don't specify 'env', this stack will be environment-agnostic.
9+
* Account/Region-dependent features and context lookups will not work,
10+
* but a single synthesized template can be deployed anywhere. */
11+
12+
/* Uncomment the next line to specialize this stack for the AWS Account
13+
* and Region that are implied by the current CLI configuration. */
14+
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
15+
16+
/* Uncomment the next line if you know exactly what Account and Region you
17+
* want to deploy the stack to. */
18+
// env: { account: '123456789012', region: 'us-east-1' },
19+
20+
/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
21+
});

iac/awscdk/cdk.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"app": "node bin/repo.js",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"jest.config.js",
11+
"package*.json",
12+
"yarn.lock",
13+
"node_modules",
14+
"test"
15+
]
16+
}
17+
}

iac/awscdk/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
testEnvironment: 'node'
3+
}

0 commit comments

Comments
 (0)