This guide provides instructions for building and deploying the load balancer application. The application consists of an app server and a load balancer, managed using AWS CDK
Before you can run the application, ensure you have the following installed:
-
Go: Version 1.16 or later.
- Download from golang.org/dl
- Installation guide
-
Node.js: Version 14 or later.
- Download from nodejs.org
- Installation guide
-
AWS CDK: Version 2.x.
- Install it globally using npm:
npm install -g aws-cdk
- AWS CDK Getting Started
- Install it globally using npm:
-
AWS CLI: Version 2.x and configured with appropriate credentials.
- Installation instructions at aws.amazon.com/cli
- Configuration guide
- Make sure you have configured your AWS CLI with:
aws configure
-
ZIP utility: To create ZIP archives.
- This is usually pre-installed on most Unix-like systems.
- For Windows, you can use 7-Zip
-
Environment Setup
- Create
.env.local
file with placeholder environment variables - Copy
.env.local
to.env
and fill in actual valuescp .env.local .env
- Modify
.env
with your specific configuration values
- Create
- Refer this in case of issues.
- Create config.yaml :
- Make a config.yaml file in the deploy_scripts directory.
- Example :
worker: 3 # minimum number of worker nodes
max_workers: 6 # maximum number of worker nodes
pool: 30 # number of allowed concurrent incoming requests
stats-dir: /tmp/stats # location of the stats directory
failure: 20 # failure percentage
GoBalance/
├── app_server/
│ ├── main.go
│ ├── other files and directories
│ └── //...
│
├── load_balancer/
│ ├── main.go
│ ├── other files and directories
│ └── //...
│
└── deploy_scripts/
│ ├── assests/
│ ├── deploy_scripts.go
| ├── config.yaml
│ ├── other files and directories
│ └── //...
├── Makefile
├── .env
└── other files
The Makefile provides the following commands:
build
: Compiles Go applications for Linux (amd64) and creates ZIP archives- Builds app_server and load_balancer binaries
- Creates ZIP archives for both components
deploy
: Deploys the application using AWS CDK without requiring manual approvaldestroy
: Destroys AWS resources created by CDKclean
: Removes compiled binaries and ZIP filestest
: Runs the test scriptall
: Performs a complete deployment cycle:- Attempts to destroy existing resources
- Cleans up files
- Builds the application
- Deploys to AWS
To compile the applications and create ZIP files, run:
make build
To deploy the application to AWS, run:
make deploy
To clean up the generated files and resources, you can run:
make clean
If you want to destroy the deployed resources, run:
make destroy
To execute the test script:
make test
To run all steps (destroy, clean, build, and deploy) in one command, run:
make all
Note: The make all
command will continue executing even if the make destroy
step fails.
- Ensure you have the correct permissions set in your AWS account.
- Check your Go and Node.js versions if you encounter compatibility issues.
- If you face issues with CDK, try running
cdk bootstrap
to set up the required resources. See CDK Bootstrapping for more information.