Feat/serverless backend lambda - #2
Merged
Merged
Conversation
…tead of in-memory state
…he local ratelimit table
There was a problem hiding this comment.
Pull request overview
This PR migrates the backend runtime from ECS Fargate + ALB to a container-image AWS Lambda exposed via a Lambda Function URL and fronted by the existing CloudFront distribution, while also introducing a DynamoDB-backed contact-form rate limiter to make rate limiting consistent across Lambda cold starts.
Changes:
- Replace the ECS/ALB backend stack with a Lambda container image + Function URL, and route
/api/*to it via CloudFront OAC (SigV4). - Add a new DynamoDB TTL table for rate limiting and switch the backend limiter implementation to DynamoDB.
- Update Terraform variables/outputs plus deployment/local-dev scripts and documentation to match the new architecture.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updates top-level architecture diagram and hosting stack description to Lambda. |
| infra/terraform/variables.tf | Replaces ECS sizing vars with Lambda memory/timeout vars. |
| infra/terraform/terraform.tfvars.example | Updates example backend sizing inputs for Lambda. |
| infra/terraform/providers.tf | Removes the random provider requirement (no longer used). |
| infra/terraform/outputs.tf | Replaces ECS/ALB outputs with the backend Lambda function name output. |
| infra/terraform/modules/database/outputs.tf | Exposes the new ratelimit table name/ARN via module outputs. |
| infra/terraform/modules/database/main.tf | Adds the DynamoDB ratelimit table with TTL enabled. |
| infra/terraform/modules/cdn/variables.tf | Replaces ALB origin variables with Lambda Function URL host + function name inputs. |
| infra/terraform/modules/cdn/main.tf | Switches /api/* origin to Lambda Function URL via OAC and adds invoke permission. |
| infra/terraform/modules/backend/variables.tf | Replaces ECS-related vars with Lambda-oriented configuration (arch/memory/timeout). |
| infra/terraform/modules/backend/outputs.tf | Exposes Lambda function name and Function URL host instead of ECS/ALB details. |
| infra/terraform/modules/backend/main.tf | Implements Lambda function + Function URL + log group, removing ECS/ALB runtime. |
| infra/terraform/modules/backend/iam.tf | Replaces ECS task/execution roles with a single Lambda execution role + policy. |
| infra/terraform/modules/backend/ecs.tf | Removes ECS cluster/task/service resources (deleted). |
| infra/terraform/modules/backend/alb.tf | Removes ALB/cert/DNS/origin-secret resources (deleted). |
| infra/terraform/main.tf | Rewires modules for Lambda backend + passes new env var for rate limit table. |
| infra/scripts/deploy-backend.sh | Updates deploy script to aws lambda update-function-code and arm64 builds. |
| infra/scripts/create-local-tables.sh | Adds creation of the local ratelimit DynamoDB table. |
| infra/README.md | Updates infra docs/runbook/diagrams and provisioning steps for Lambda + Function URL. |
| docker-compose.yml | Adds RATELIMIT_TABLE_NAME env var for local services. |
| backend/tests/unit/utils/test_rate_limit.py | Replaces in-memory limiter tests with moto-backed DynamoDB limiter tests. |
| backend/tests/conftest.py | Adds ratelimit table env + test table creation. |
| backend/src/utils/rate_limit.py | Replaces in-memory limiter with DynamoDB-backed fixed-window limiter + dependency. |
| backend/src/config.py | Adds ratelimit_table_name setting/env mapping. |
| backend/README.md | Updates backend documentation for Lambda runtime + DynamoDB-backed rate limiting. |
| backend/Dockerfile | Adds AWS Lambda Web Adapter extension and readiness configuration. |
| backend/.env.example | Adds RATELIMIT_TABLE_NAME and updates rate-limit docs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+58
to
61
| resource "aws_lambda_function_url" "backend" { | ||
| function_name = aws_lambda_function.backend.function_name | ||
| authorization_type = "AWS_IAM" | ||
| } |
Comment on lines
+45
to
49
| echo "Updating Lambda function ${FUNCTION_NAME} to image ${GIT_SHA}..." | ||
| aws lambda update-function-code \ | ||
| --function-name "${FUNCTION_NAME}" \ | ||
| --image-uri "${ECR_REPOSITORY_URL}:${GIT_SHA}" \ | ||
| --region "${AWS_REGION}" > /dev/null |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.