This project demonstrates a production-ready setup for deploying a Hono application using Bun runtime on AWS ECS Fargate, with infrastructure managed by Terraform.
- Hono Web Framework: Fast, lightweight, and TypeScript-first web framework
- Bun Runtime: High-performance JavaScript/TypeScript runtime
- Infrastructure as Code: Complete AWS infrastructure using Terraform
- Production Ready: Includes load balancing and HTTPS (could easily be modified to include auto-scaling)
- CloudFlare Integration: DNS management and additional security features
- Bun installed locally
- Docker installed
- Terraform installed
- AWS CLI configured with appropriate credentials
- Cloudflare account and API token (for DNS management)
- Install dependencies:
bun install
- Start the development server:
bun run dev
- Open http://localhost:3000 in your browser
- Copy the example Terraform variables file:
cp terraform/terraform.tfvars.example terraform/terraform.tfvars
- Update
terraform.tfvars
with your values:
cloudflare_api_token = "your-token"
cloudflare_zone_id = "your-zone-id"
domain_name = "your-domain.com"
aws_region = "your-preferred-region"
project_name = "your-project-name"
environment = "production"
- Initialize Terraform:
cd terraform
terraform init
- Deploy the infrastructure:
terraform plan # Review the changes
terraform apply # Apply the changes
The deployment process is fully automated through Terraform. After applying the Terraform configuration, the application will be automatically deployed to ECS Fargate. Any subsequent updates can be deployed by:
- Making your code changes
- Running
terraform apply
in the terraform directory
Terraform will handle:
- Building and pushing the Docker image to ECR
- Updating the ECS service with the new image
- Managing the deployment rollout
Note: While this demo uses Terraform to build and push Docker images for simplicity, in a production environment it's recommended to handle image building and pushing through a proper CI/CD pipeline (like GitHub Actions, GitLab CI, or AWS CodePipeline). This separation of concerns allows for better versioning, testing, and deployment strategies.
- VPC: Isolated network with public and private subnets
- ECS Fargate: Serverless container orchestration
- Application Load Balancer: HTTP/HTTPS traffic handling
- CloudFlare: DNS management, SSL/TLS, and security features
- ECR: Docker image repository
- CloudWatch: Logging and monitoring
- S3: Load balancer access logs storage
- HTTPS-only traffic
- CloudFlare security headers
- Private subnets for containers
- Security groups for fine-grained access control
- SSL/TLS certificate management
- Load balancer access logging
The following environment variables are available to the application:
NODE_ENV
: Set automatically based on environmentDEPLOYMENT_TIMESTAMP
: Set automatically during deployment
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.