A starter project for developing and deploying AWS Lambda functions with shared libraries and managed dependencies.
- Multiple Lambda functions with shared code
- Shared libraries with proper dependency management
- Lambda layers for packaging dependencies and shared libraries
- CLI commands for building, testing, and local invocation
- Integration with
uvfor Python dependency management - AWS SAM CLI integration for local testing
- AWS CDK and SAM CLI support for infrastructure as code deployment
aws-lambda-starter/
├── cli/ # CLI and utilities
├── lambdas/ # Lambda functions
│ ├── hello_world/ # Hello World Lambda
│ └── data_processor/ # Data Processor Lambda
├── libs/ # Shared libraries
│ ├── lib_common/ # Common utilities
│ └── lib_utils/ # Utility functions
├── main.py # CLI entry point
└── pyproject.toml # Project configuration
└── cdk/ # (Optional) Generated CDK stack. don't manually edit anything here.
└── template.yaml # (Optional) template for deployment via AWS SAM
uvpackage and project manager- Python 3.13 (automatically installed by
uv)
- Clone the repository:
git clone https://github.com/armujahid/aws-lambda-starter.git cd aws-lambda-starter
There are two ways to run commands in this project:
This project recommends using uv run to execute CLI commands. This approach automatically handles virtual environment management and dependency installation for you without any additional setup:
uv run main.py <command>If you prefer to use Python directly, you need to:
-
Install all dependencies first:
uv sync
-
Activate your virtual environment:
source .venv/bin/activate -
Then run the commands directly:
python main.py <command>
uv run main.py --helpuv run main.py list-lambdasuv run main.py list-libsBuild a combined layer with dependencies and shared libraries:
uv run main.py build-layerOr build separate layers:
uv run main.py build-layer --no-combined --include-libs
uv run main.py build-layer --no-combined --include-depsuv run main.py build-lambda hello_worldRun all tests:
uv run main.py testRun tests for a specific library:
uv run main.py test lib_commonRun tests with verbose output:
uv run main.py test --verboseRun tests with coverage reporting:
uv run main.py test --coverageInvoke a Lambda function locally using AWS SAM CLI:
uv run main.py invoke-local hello_worldWith a custom event file:
uv run main.py invoke-local hello_world --event-file path/to/event.json-
Create a new directory in the
lambdasdirectory:mkdir -p lambdas/new_function
-
Create an
app.pyfile with a handler function:import lib_common import lib_utils def handler(event, context): # Your code here return lib_utils.create_success_response({"message": "Success"})
-
Create an
event.jsonfile for testing.
-
Create a new directory in the
libsdirectory:mkdir -p libs/lib_new/src/lib_new libs/lib_new/tests
-
Create a
pyproject.tomlfile:[build-system] requires = ["setuptools>=42", "wheel"] build-backend = "setuptools.build_meta" [project] name = "lib_new" version = "0.1.0" description = "New shared library" requires-python = ">=3.13" [project.dependencies] # Your dependencies here
-
Create an
__init__.pyfile inlibs/lib_new/src/lib_new/. -
Create test files in
libs/lib_new/tests/.
This project provides two methods for deploying your Lambda functions to AWS:
The project includes a dynamic CDK stack generator that automatically discovers all Lambda functions and deploys them with the shared layer.
# Deploy all Lambda functions with the default stack name (LambdaStack)
uv run main.py deploy-cdk
# Deploy specific Lambda functions
uv run main.py deploy-cdk --lambda hello_world --lambda data_processor
# Deploy with AWS profile and region
uv run main.py deploy-cdk --profile myprofile --region us-west-2
# Deploy with custom environment variables for Lambda functions
uv run main.py deploy-cdk --env API_URL=https://example.com --env LOG_LEVEL=DEBUG
# Deploy with a custom stack name
uv run main.py deploy-cdk --stack-name MyCustomStack
# Deploy without rebuilding the Lambda layer
uv run main.py deploy-cdk --no-build-layerThe CDK deployment automatically:
- Builds all Lambda functions
- Creates a shared layer with dependencies and shared libraries
- Sets up IAM roles and permissions
- Configures environment variables
- Deploys the stack to your AWS account
To delete the CDK stack:
# Delete the CDK stack
uv run cdk destroy --app "python cdk/app.py"You can also use AWS SAM for deploying the project:
# Deploy with interactive prompts for parameters
sam deploy --guided
# Deploy using previously saved parameters
sam deploySAM deployment uses the template.yaml file in the project root to define the infrastructure.
To delete the SAM stack:
# Delete the SAM stack
sam deleteMIT