This guide configures the full AWS infrastructure for the Phishing Detection System using CLI commands only.
- AWS CLI v2:
pip install awsclior install from AWS - Terraform >= 1.5: Install Terraform
- AWS credentials configured:
aws configure
Interactive (recommended):
# Prompts for AWS keys (if needed), DB password, API_KEY_SECRET, JWT_SECRET
./scripts/configure-credentials.sh
source .env.credentials
./scripts/aws-setup.sh allManual:
# 1. aws configure # Enter your Access Key ID and Secret
# 2. Set required vars
export TF_VAR_db_password="your-secure-password"
export SSM_API_KEY_SECRET="your-api-key-secret"
export SSM_JWT_SECRET="your-jwt-secret"
# 3. Run full setup
./scripts/aws-setup.sh all./scripts/aws-setup.sh checkCreate a dedicated IAM user for Terraform and CI/CD:
# Create user
aws iam create-user --user-name phishing-detection-deployer
# Create and attach policy (use scripts/aws-iam-policy.json)
aws iam put-user-policy \
--user-name phishing-detection-deployer \
--policy-name PhishingDetectionDeploy \
--policy-document file://scripts/aws-iam-policy.json
# Create access key
aws iam create-access-key --user-name phishing-detection-deployer
# Store AccessKeyId and SecretAccessKey securelyFor production, prefer an IAM role with broader Terraform permissions (EC2, RDS, ECS, VPC, S3, etc.); the policy above covers CI/CD and ECR. Terraform needs full permissions for the resources it creates.
Creates S3 bucket and DynamoDB table for Terraform state:
./scripts/aws-setup.sh bootstrapOr manually:
export AWS_REGION=ap-south-1
aws s3 mb s3://phishing-detection-terraform-state-1768755350 --region $AWS_REGION
aws s3api put-bucket-versioning \
--bucket phishing-detection-terraform-state-1768755350 \
--versioning-configuration Status=Enabled
aws dynamodb create-table \
--table-name terraform-state-lock \
--attribute-definitions AttributeName=LockID,AttributeType=S \
--key-schema AttributeName=LockID,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--region $AWS_REGION./scripts/aws-setup.sh ecrCreates 9 repositories: api-gateway, detection-api, threat-intel, extension-api, sandbox-service, learning-pipeline, nlp-service, url-service, visual-service.
export TF_VAR_db_password="your-secure-password"
export ENVIRONMENT=dev # or prod
./scripts/aws-setup.sh terraformTerraform provisions:
- VPC – Public/private subnets, NAT gateways, security groups
- RDS – PostgreSQL 16 (phishing_detection DB)
- ElastiCache – Redis
- S3 – Models, training data, logs, artifacts buckets
- ECS – Fargate cluster, ALB, 8+ microservices
- CloudWatch – Log groups
export SSM_API_KEY_SECRET="your-api-key-secret"
export SSM_JWT_SECRET="your-jwt-secret"
./scripts/aws-setup.sh secretsOr manually:
aws ssm put-parameter --name "/phishing-detection/dev/API_KEY_SECRET" \
--value "your-value" --type SecureString --overwrite --region ap-south-1
aws ssm put-parameter --name "/phishing-detection/dev/JWT_SECRET" \
--value "your-value" --type SecureString --overwrite --region ap-south-1./scripts/aws-setup.sh modelsSyncs local models from backend/ml-services/*/models/ to s3://phishing-detection-models-{env}/.
| Variable | Description | Default |
|---|---|---|
AWS_REGION |
AWS region | ap-south-1 |
ENVIRONMENT |
Environment (dev/staging/prod) | dev |
TF_VAR_db_password |
RDS master password | required |
TF_STATE_BUCKET |
Terraform state bucket | phishing-detection-terraform-state-1768755350 |
SSM_API_KEY_SECRET |
For SSM secrets step | optional |
SSM_JWT_SECRET |
For SSM secrets step | optional |
For production, use a separate tfvars file:
cp backend/infrastructure/terraform/environments/prod.tfvars.example \
backend/infrastructure/terraform/environments/prod.tfvars
# Edit prod.tfvars: set certificate_arn for HTTPS, stronger db/redis instance typesThen:
export ENVIRONMENT=prod
export TF_VAR_db_password="strong-production-password"
./scripts/aws-setup.sh allSSL: Request an ACM certificate for your domain, then set certificate_arn in prod.tfvars.
- Get ALB DNS:
cd backend/infrastructure/terraform && terraform output alb_dns_name - Push Docker images: Run CI/CD pipeline or
docker build+docker pushto ECR - Create API key: Run
backend/shared/scripts/create-initial-setup.tsand store in GitHub secrets asTEST_API_KEY - Configure GitHub Secrets:
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_ACCOUNT_ID,TF_VAR_DB_PASSWORD,TEST_API_KEY
Bucket name taken? If S3 returns BucketAlreadyExists, the name is taken globally. Use a unique name:
export TF_STATE_BUCKET=phishing-detection-tfstate-$(aws sts get-caller-identity --query AccountId --output text)
Then update backend/infrastructure/terraform/backend.tfvars and the backend "s3" block in main.tf to match.
| Issue | Fix |
|---|---|
aws: command not found |
Install AWS CLI v2 |
An error occurred (InvalidClientTokenId) |
Run aws configure with valid credentials |
Error acquiring the state lock |
Wait for other Terraform run, or force-unlock: terraform force-unlock LOCK_ID |
| ECS tasks fail to start | Ensure ECR images exist (:latest); run CI pipeline to build/push |
| RDS connection refused | Check security groups allow ECS → RDS on 5432 |