Skip to content

HackerM0nk/localstack-aws-cloud-infra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LocalStack AWS Infrastructure Prototype

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.

πŸ—οΈ Infrastructure Components

  • 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

πŸ“‹ Prerequisites

πŸš€ Quick Start

1. Setup LocalStack and Initialize

./scripts/setup.sh

This script will:

  • βœ… Check Docker and Terraform installation
  • βœ… Start LocalStack container
  • βœ… Initialize Terraform

2. Deploy Infrastructure

./scripts/deploy.sh

This script will:

  • βœ… Plan Terraform deployment
  • βœ… Apply infrastructure configuration
  • βœ… Display infrastructure details
  • βœ… Verify EKS cluster creation

3. Clean Up

./scripts/cleanup.sh

This script will:

  • 🧹 Destroy all Terraform resources
  • 🧹 Stop LocalStack container
  • 🧹 Optionally remove data volumes and Terraform state

πŸ“ Project Structure

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

βš™οΈ Configuration

Terraform Variables

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

LocalStack Services

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)

πŸ” Testing and Verification

Check LocalStack Health

curl http://localhost:4566/_localstack/health

List AWS Resources

# 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

Check Kubernetes Resources

# 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

Access Nginx Application

# Port forward to access nginx
kubectl port-forward -n demo service/nginx-service 8080:80

# Then visit: http://localhost:8080

View Terraform Outputs

cd terraform
terraform output

πŸ› οΈ Manual Steps

1. Start LocalStack Manually

docker-compose up -d

2. Deploy with Terraform

cd terraform
terraform init
terraform plan
terraform apply

3. Verify Deployment

terraform output

🌐 LocalStack Dashboard

Access the LocalStack web interface at: http://localhost:4566

πŸ“ Notes

  • 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

🚨 Troubleshooting

LocalStack Not Starting

# Check Docker status
docker ps
# Check LocalStack logs
docker-compose logs localstack

Terraform Issues

# Refresh Terraform state
terraform refresh
# Force unlock if needed
terraform force-unlock LOCK_ID

Port Conflicts

If port 4566 is in use, modify the port mapping in docker-compose.yml:

ports:
  - "4567:4566"  # Change external port

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Test your changes locally
  4. Submit a pull request

πŸ“„ License

This project is provided as-is for demonstration purposes.


Happy Local AWS Development! πŸš€# localstack-aws-cloud-infra

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published