AWS Lambda Project Structure
A scalable and maintainable folder structure for AWS Lambda projects
File Structure
- src
- functions
- users
- get.js
- create.js
- update.js
- delete.js
- auth
- login.js
- register.js
- authorizer.js
- webhooks
- stripe.js
- github.js
- layers
- common
- utils.js
- constants.js
- aws-sdk
- dynamodb.js
- s3.js
- ses.js
- middleware
- cors.js
- auth.js
- validation.js
- models
- User.js
- BaseModel.js
- infrastructure
- cloudformation
- dynamodb.yml
- s3.yml
- terraform
- main.tf
- variables.tf
- tests
- unit
- integration
- e2e
- fixtures
- scripts
- deploy.sh
- seed-data.js
- package.json
- serverless.yml
- webpack.config.js
- .env.example
- README.md
Directory Structure Explanation
src/functions/users/
User-related Lambda functions organized by HTTP method and operation.
src/functions/auth/
Authentication-related functions including login, registration, and authorization.
functions/auth/authorizer.js
Custom Lambda authorizer for API Gateway authentication and authorization.
src/functions/webhooks/
Webhook handlers for processing events from external services.
src/layers/
Lambda layers for sharing code and dependencies across multiple functions.
layers/common/
Common utilities and constants shared across Lambda functions.
src/middleware/
Middleware functions for cross-cutting concerns like CORS, authentication, and validation.
src/models/
Data model classes for representing business entities and database interactions.
infrastructure/
Infrastructure as Code definitions using CloudFormation or Terraform.
infrastructure/cloudformation/
CloudFormation templates for AWS resource provisioning.
scripts/
Deployment and utility scripts for automation and data seeding.
webpack.config.js
Webpack configuration for bundling and optimizing Lambda function code.