-
-
Couldn't load subscription status.
- Fork 245
Migrate OWASP Nest to Zappa for serverless deployment #2431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arkid15r
merged 38 commits into
OWASP:feature/nest-zappa-migration
from
rudransh-shrivastava:feature/zappa-migration
Oct 26, 2025
Merged
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
0975e0a
Install zappa and initial example configuration
rudransh-shrivastava aa4eea0
add temporary IaC code for testing
rudransh-shrivastava 18b8adb
Update code
rudransh-shrivastava 6311813
Merge branch 'main' into feature/zappa-migration
rudransh-shrivastava 481b928
Remove IAM and let Zappa manage it
rudransh-shrivastava ee1edb6
add README
rudransh-shrivastava 90e24e1
add RDS proxy, pre-commit hooks, clean-up code
rudransh-shrivastava e618808
feat: add ecs tasks
rudransh-shrivastava 6220c24
refactor/clean cache module
rudransh-shrivastava 9495dfd
refactor/clean database module
rudransh-shrivastava df72c9a
refactor/clean ecs module
rudransh-shrivastava 619400e
refactor/clean networking module
rudransh-shrivastava b8b49fa
address Sonar Qube bot suggestions
rudransh-shrivastava 8c3569d
keep some Sonar Qube bot suggestions but add #NOSONAR
rudransh-shrivastava 91b12e7
add terraform dictionary
rudransh-shrivastava 92469ac
refactor/clean security module
rudransh-shrivastava 1a66c4f
fix pre-commit hooks and add terraform_validate
rudransh-shrivastava 6994e33
add SHA hash and remove terraform_validate
rudransh-shrivastava a41221f
refactor/clean storage module
rudransh-shrivastava 1165166
Update docs
rudransh-shrivastava cc80292
add S3 support for load-data task
rudransh-shrivastava c694c57
Update README and necessary examples
rudransh-shrivastava 753e234
coderabbit suggestions
rudransh-shrivastava 16445dc
Update code: install awscli before invoking aws in task
rudransh-shrivastava 536e615
update README
rudransh-shrivastava 206e60e
NOSONAR
rudransh-shrivastava 0a8b4ea
Merge branch 'main' into feature/zappa-migration
rudransh-shrivastava 748ed52
update README
rudransh-shrivastava f71861c
fix spell check
rudransh-shrivastava e785a42
Update README
rudransh-shrivastava bc3737e
fix: typo
rudransh-shrivastava e51d34b
remove immutable tagged images
rudransh-shrivastava d419073
fix: load-data task fail due to no permissions
rudransh-shrivastava a347969
fix spell check: add PYTHONPATH
rudransh-shrivastava 88af956
add AWS CLI
rudransh-shrivastava 5be1083
add set -e
rudransh-shrivastava 9650e5e
Update code
arkid15r d4f7ddd
Merge branch 'feature/nest-zappa-migration' into pr/rudransh-shrivast…
arkid15r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "staging": { | ||
| "app_function": "wsgi.application", | ||
| "django_settings": "settings.staging", | ||
| "environment_variables": { | ||
| "DJANGO_ALGOLIA_APPLICATION_ID": "${DJANGO_ALGOLIA_APPLICATION_ID}", | ||
| "DJANGO_ALGOLIA_WRITE_API_KEY": "${DJANGO_ALGOLIA_WRITE_API_KEY}", | ||
| "DJANGO_ALLOWED_HOSTS": "${DJANGO_ALLOWED_HOSTS}", | ||
| "DJANGO_AWS_ACCESS_KEY_ID": "${DJANGO_AWS_ACCESS_KEY_ID}", | ||
| "DJANGO_AWS_SECRET_ACCESS_KEY": "${DJANGO_AWS_SECRET_ACCESS_KEY}", | ||
| "DJANGO_CONFIGURATION": "Staging", | ||
| "DJANGO_DB_HOST": "${DJANGO_DB_HOST}", | ||
| "DJANGO_DB_NAME": "${DJANGO_DB_NAME}", | ||
| "DJANGO_DB_USER": "${DJANGO_DB_USER}", | ||
| "DJANGO_DB_PORT": "${DJANGO_DB_PORT}", | ||
| "DJANGO_DB_PASSWORD": "${DJANGO_DB_PASSWORD}", | ||
| "DJANGO_OPEN_AI_SECRET_KEY": "${DJANGO_OPEN_AI_SECRET_KEY}", | ||
| "DJANGO_REDIS_HOST": "${DJANGO_REDIS_HOST}", | ||
| "DJANGO_REDIS_PASSWORD": "${DJANGO_REDIS_PASSWORD}", | ||
| "DJANGO_SECRET_KEY": "${DJANGO_SECRET_KEY}", | ||
| "DJANGO_SENTRY_DSN": "${DJANGO_SENTRY_DSN}", | ||
| "DJANGO_SLACK_BOT_TOKEN": "${DJANGO_SLACK_BOT_TOKEN}", | ||
| "DJANGO_SLACK_SIGNING_SECRET": "${DJANGO_SLACK_SIGNING_SECRET}" | ||
| }, | ||
| "manage_roles": true, | ||
| "project_name": "nest-backend", | ||
| "runtime": "python3.13", | ||
rudransh-shrivastava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "s3_bucket": "${ZAPPA_S3_BUCKET}", | ||
| "slim_handler": true, | ||
| "vpc_config": { | ||
| "SecurityGroupIds": ["${VPC_SECURITY_GROUP}"], | ||
| "SubnetIds": ["${VPC_SUBNET_A}", "${VPC_SUBNET_B}"] | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| module "networking" { | ||
| source = "./modules/networking" | ||
|
|
||
| vpc_cidr = var.vpc_cidr | ||
| public_subnet_cidrs = var.public_subnet_cidrs | ||
| private_subnet_cidrs = var.private_subnet_cidrs | ||
| availability_zones = var.availability_zones | ||
| project_name = var.project_name | ||
| environment = var.environment | ||
| } | ||
|
|
||
| module "security" { | ||
| source = "./modules/security" | ||
|
|
||
| vpc_id = module.networking.vpc_id | ||
| db_port = var.db_port | ||
| redis_port = var.redis_port | ||
| project_name = var.project_name | ||
| environment = var.environment | ||
| } | ||
|
|
||
| module "storage" { | ||
| source = "./modules/storage" | ||
|
|
||
| zappa_s3_bucket = var.zappa_s3_bucket | ||
| project_name = var.project_name | ||
| environment = var.environment | ||
| } | ||
|
|
||
|
|
||
|
|
||
| module "database" { | ||
| source = "./modules/database" | ||
|
|
||
| db_allocated_storage = var.db_allocated_storage | ||
| db_engine_version = var.db_engine_version | ||
| db_instance_class = var.db_instance_class | ||
| db_name = var.db_name | ||
| db_password = var.db_password | ||
| db_username = var.db_username | ||
| db_subnet_ids = module.networking.private_subnet_ids | ||
| security_group_ids = [module.security.rds_sg_id] | ||
| project_name = var.project_name | ||
| environment = var.environment | ||
| } | ||
|
|
||
| module "cache" { | ||
| source = "./modules/cache" | ||
|
|
||
| redis_engine_version = var.redis_engine_version | ||
| redis_node_type = var.redis_node_type | ||
| redis_num_cache_nodes = var.redis_num_cache_nodes | ||
| redis_port = var.redis_port | ||
| subnet_ids = module.networking.private_subnet_ids | ||
| security_group_ids = [module.security.redis_sg_id] | ||
| project_name = var.project_name | ||
| environment = var.environment | ||
| } | ||
rudransh-shrivastava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # ElastiCache Subnet Group | ||
| resource "aws_elasticache_subnet_group" "main" { | ||
| name = "${var.project_name}-${var.environment}-cache-subnet-group" | ||
| subnet_ids = var.subnet_ids | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-${var.environment}-cache-subnet-group" | ||
| } | ||
| } | ||
|
|
||
| # Random auth token for Redis (if not provided) | ||
| resource "random_password" "redis_auth_token" { | ||
| count = var.redis_auth_token == null || var.redis_auth_token == "" ? 1 : 0 | ||
|
|
||
| length = 32 | ||
| special = true | ||
| # Redis auth token has specific requirements | ||
| override_special = "!&#$^<>-" | ||
| } | ||
|
|
||
| # ElastiCache Redis Replication Group | ||
| resource "aws_elasticache_replication_group" "main" { | ||
| replication_group_id = "${var.project_name}-${var.environment}-cache" | ||
| description = "${var.project_name} ${var.environment} Redis cache" | ||
|
|
||
| engine = "redis" | ||
| engine_version = var.redis_engine_version | ||
| node_type = var.redis_node_type | ||
| port = var.redis_port | ||
| parameter_group_name = "default.redis7" | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Cluster configuration | ||
| num_cache_clusters = var.redis_num_cache_nodes | ||
|
|
||
| # Network configuration | ||
| subnet_group_name = aws_elasticache_subnet_group.main.name | ||
| security_group_ids = var.security_group_ids | ||
|
|
||
| # Security | ||
| at_rest_encryption_enabled = true | ||
| transit_encryption_enabled = true | ||
| auth_token = var.redis_auth_token != null && var.redis_auth_token != "" ? var.redis_auth_token : random_password.redis_auth_token[0].result | ||
|
|
||
| # Maintenance and backups | ||
| snapshot_retention_limit = 5 | ||
| snapshot_window = "03:00-05:00" | ||
| maintenance_window = "mon:05:00-mon:07:00" | ||
|
|
||
| # Automatic failover (requires at least 2 nodes) | ||
| automatic_failover_enabled = var.redis_num_cache_nodes > 1 | ||
|
|
||
| # Enable automatic minor version upgrades | ||
| auto_minor_version_upgrade = true | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-${var.environment}-redis" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| output "redis_primary_endpoint" { | ||
| description = "The primary endpoint of the Redis replication group" | ||
| value = aws_elasticache_replication_group.main.primary_endpoint_address | ||
| } | ||
|
|
||
| output "redis_auth_token" { | ||
| description = "The auth token for Redis" | ||
| value = random_password.redis_auth_token[0].result | ||
| sensitive = true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| variable "environment" { | ||
| description = "The environment (e.g., staging, production)" | ||
| type = string | ||
| } | ||
|
|
||
| variable "project_name" { | ||
| description = "The name of the project" | ||
| type = string | ||
| } | ||
|
|
||
| variable "redis_auth_token" { | ||
| description = "The auth token for Redis" | ||
| type = string | ||
| sensitive = true | ||
| default = null | ||
| } | ||
|
|
||
| variable "redis_engine_version" { | ||
| description = "The version of the Redis engine" | ||
| type = string | ||
| } | ||
|
|
||
| variable "redis_node_type" { | ||
| description = "The node type for the Redis cache" | ||
| type = string | ||
| } | ||
|
|
||
| variable "redis_num_cache_nodes" { | ||
| description = "The number of cache nodes in the Redis cluster" | ||
| type = number | ||
| } | ||
|
|
||
| variable "redis_port" { | ||
| description = "The port for the Redis cache" | ||
| type = number | ||
| } | ||
|
|
||
| variable "security_group_ids" { | ||
| description = "A list of security group IDs to associate with the Redis cache" | ||
| type = list(string) | ||
| } | ||
|
|
||
| variable "subnet_ids" { | ||
| description = "A list of subnet IDs for the cache subnet group" | ||
| type = list(string) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # DB Subnet Group | ||
| resource "aws_db_subnet_group" "main" { | ||
| name = "${var.project_name}-${var.environment}-db-subnet-group" | ||
| subnet_ids = var.db_subnet_ids | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-${var.environment}-db-subnet-group" | ||
| } | ||
| } | ||
|
|
||
| # Random password for RDS (if not provided) | ||
| resource "random_password" "db_password" { | ||
| count = var.db_password == null || var.db_password == "" ? 1 : 0 | ||
|
|
||
| length = 32 | ||
| special = true | ||
| # Avoid special characters that might cause issues | ||
| override_special = "!#$%&*()-_=+[]{}<>:?" | ||
| } | ||
|
|
||
| # RDS PostgreSQL Instance | ||
| resource "aws_db_instance" "main" { | ||
| identifier = "${var.project_name}-${var.environment}-db" | ||
| engine = "postgres" | ||
| engine_version = var.db_engine_version | ||
| instance_class = var.db_instance_class | ||
| allocated_storage = var.db_allocated_storage | ||
| storage_type = "gp3" | ||
| storage_encrypted = true | ||
|
|
||
| db_name = var.db_name | ||
| username = var.db_username | ||
| password = var.db_password != null && var.db_password != "" ? var.db_password : random_password.db_password[0].result | ||
|
|
||
| db_subnet_group_name = aws_db_subnet_group.main.name | ||
| vpc_security_group_ids = var.security_group_ids | ||
| publicly_accessible = false | ||
|
|
||
| backup_retention_period = 7 | ||
| backup_window = "03:00-04:00" | ||
| maintenance_window = "mon:04:00-mon:05:00" | ||
|
|
||
| # Enable automated backups | ||
| skip_final_snapshot = true | ||
| final_snapshot_identifier = "${var.project_name}-${var.environment}-final-snapshot-${formatdate("YYYY-MM-DD-hhmm", timestamp())}" | ||
| copy_tags_to_snapshot = true | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Performance Insights | ||
| enabled_cloudwatch_logs_exports = ["postgresql", "upgrade"] | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-${var.environment}-postgres" | ||
| } | ||
|
|
||
| lifecycle { | ||
| ignore_changes = [ | ||
| final_snapshot_identifier | ||
| ] | ||
| } | ||
| } | ||
rudransh-shrivastava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| output "db_instance_endpoint" { | ||
| description = "The endpoint of the RDS instance" | ||
| value = aws_db_instance.main.endpoint | ||
| } | ||
|
|
||
| output "db_password" { | ||
| description = "The password for the RDS database" | ||
| value = random_password.db_password[0].result | ||
| sensitive = true | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.