This project demonstrates how to create AWS infrastructure locally using LocalStack and Terraform. It sets up a complete VPC with subnets, NAT gateways, and an EKS cluster - all running locally without incurring AWS costs.
- VPC: 10.0.0.0/16 CIDR with DNS support
- Subnets: 2 public and 2 private subnets across availability zones
- Networking: Internet Gateway, NAT Gateways, Route Tables
- EKS Cluster: Kubernetes cluster with managed node group
- Security Groups: Proper security configurations
- IAM Roles: Required roles and policies for EKS
- Nginx Application: Sample web application deployed in EKS
./scripts/setup.shThis script will:
- β Check Docker and Terraform installation
- β Start LocalStack container
- β Initialize Terraform
./scripts/deploy.shThis script will:
- β Plan Terraform deployment
- β Apply infrastructure configuration
- β Display infrastructure details
- β Verify EKS cluster creation
./scripts/cleanup.shThis script will:
- π§Ή Destroy all Terraform resources
- π§Ή Stop LocalStack container
- π§Ή Optionally remove data volumes and Terraform state
localstack-aws-infra/
βββ docker-compose.yml # LocalStack container configuration
βββ terraform/
β βββ providers.tf # AWS provider with LocalStack endpoints
β βββ variables.tf # Input variables
β βββ vpc.tf # VPC, subnets, gateways, routing
β βββ iam.tf # IAM roles and policies
β βββ eks.tf # EKS cluster and node groups
β βββ outputs.tf # Infrastructure outputs
βββ k8s/
β βββ nginx-namespace.yaml # Kubernetes namespace
β βββ nginx-configmap.yaml # Custom nginx page content
β βββ nginx-deployment.yaml # Nginx deployment
β βββ nginx-service.yaml # LoadBalancer service
βββ scripts/
β βββ setup.sh # Environment setup
β βββ deploy.sh # Infrastructure deployment
β βββ configure-kubectl.sh # Kubectl configuration and app deployment
β βββ cleanup.sh # Resource cleanup
βββ architecture-diagram.excalidraw # Infrastructure diagram
βββ README.md
You can customize the infrastructure by modifying variables in terraform/variables.tf:
| Variable | Default | Description |
|---|---|---|
project_name |
localstack-demo |
Name prefix for resources |
vpc_cidr |
10.0.0.0/16 |
VPC CIDR block |
public_subnet_count |
2 |
Number of public subnets |
private_subnet_count |
2 |
Number of private subnets |
cluster_name |
localstack-eks |
EKS cluster name |
cluster_version |
1.27 |
Kubernetes version |
node_group_instance_type |
t3.medium |
Worker node instance type |
The setup enables these LocalStack services:
- EC2 (for VPC and subnets)
- EKS (for Kubernetes cluster)
- IAM (for roles and policies)
- STS (for token service)
- CloudWatch Logs
- EFS (Elastic File System)
- ELB (Elastic Load Balancing)
curl http://localhost:4566/_localstack/health# Set AWS CLI to use LocalStack
export AWS_ENDPOINT_URL=http://localhost:4566
export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test
export AWS_DEFAULT_REGION=us-east-1
# List VPCs
aws ec2 describe-vpcs
# List EKS clusters
aws eks list-clusters
# Describe EKS cluster
aws eks describe-cluster --name localstack-eks# Set kubeconfig for LocalStack
export KUBECONFIG=~/.kube/config-localstack
# Check cluster info
kubectl cluster-info
# View nginx pods
kubectl get pods -n demo
# View services
kubectl get services -n demo
# Check deployment status
kubectl get deployments -n demo# Port forward to access nginx
kubectl port-forward -n demo service/nginx-service 8080:80
# Then visit: http://localhost:8080cd terraform
terraform outputdocker-compose up -dcd terraform
terraform init
terraform plan
terraform applyterraform outputAccess the LocalStack web interface at: http://localhost:4566
- Local Development: All resources are created locally in LocalStack
- No AWS Costs: No actual AWS resources are created
- Data Persistence: LocalStack data persists in Docker volumes
- Resource Limits: LocalStack Community edition has some limitations
- Security: Uses dummy AWS credentials for local development
# Check Docker status
docker ps
# Check LocalStack logs
docker-compose logs localstack# Refresh Terraform state
terraform refresh
# Force unlock if needed
terraform force-unlock LOCK_IDIf port 4566 is in use, modify the port mapping in docker-compose.yml:
ports:
- "4567:4566" # Change external port- Fork the repository
- Create a feature branch
- Test your changes locally
- Submit a pull request
This project is provided as-is for demonstration purposes.
Happy Local AWS Development! π# localstack-aws-cloud-infra