A Python development framework for writing, testing, and deploying AWS Lambda functions. Provides local execution environment that simulates Lambda's event and context objects, Cognito integration for testing authenticated APIs, API Gateway management via Swagger, and Makefile-driven deployment workflow.
Use case: Rapid Lambda function development with local testing before deploying to AWS.
- Language: Python 2.7 (legacy; may need upgrade to Python 3.9+)
- AWS Services: Lambda, API Gateway, Cognito, S3
- Tools:
aws-cli1.9+ — AWS resource managementaws-apigateway-importer— Swagger-based API deployment (Git submodule)pip6+ — Python package management
- Testing:
unittestmodule - Build:
Makefile— all operations (build, test, deploy, run)
# Setup
pip install -r requirements.txt
aws configure # Set up AWS credentials
# Create a new Lambda function
# 1. Create src/<function-name>/ directory
# 2. Add src/<function-name>/index.py with handler function
# 3. Add src/<function-name>/__init__.py
# Run locally
make run/<function> EVENT=events/test.json
# Create function in AWS Lambda (first time)
make create/<function>
# Deploy (update existing function)
make deploy/<function>
# Run unit tests
make test
make test/<specific-test>
# Connect to secure API via Cognito
make connect ENDPOINT=/my_endpoint METHOD=GET QUERY="param=value"src/— Lambda function source code (one subdirectory per function)src/<function>/index.py— Entry point withhandler(event, context)functionsrc/<function>/__init__.py— Required for Python module
lib/— Shared libraries imported by multiple functionstests/— Unit tests (files namedtest*.py)swagger/— Swagger YAML files for API Gateway definitionscripts/— Utility scriptsrequirements.txt— Python dependencies (installed into each function's ZIP)Makefile— Build, test, deploy automationrun.py— Local Lambda simulator scriptconnect.py— API Gateway + Cognito test client
External:
- AWS Lambda — function execution environment
- AWS API Gateway — HTTP API layer
- AWS Cognito — authentication and temporary credentials
- AWS S3 — function code storage (ZIP files uploaded to S3 before Lambda update)
Internal:
lib/directory — shared code copied into each function's ZIP.envfile — environment variables and secrets (downloaded from S3)
Lambda function structure:
# src/<function>/index.py
def handler(event, context):
# event: API Gateway event or custom event JSON
# context: Lambda context object (simulated locally)
return {
"statusCode": 200,
"body": json.dumps({"message": "success"})
}Makefile commands:
make create/<function>— Create new Lambda function in AWSmake deploy/<function> [ENV=prod]— Update existing Lambda functionmake run/<function> [EVENT=file] [VERBOSE=1]— Run locallymake dist/<function>.zip— Build deployment ZIPmake test— Run all unit testsmake connect ENDPOINT=/path METHOD=GET— Test API Gateway with Cognito auth
Environment variables (from .env file in S3):
API_HOST— API Gateway hostAPI_ENDPOINT— Full API Gateway URLAPI_STAGE— Stage name (e.g.,/dev,/prod)IDENTITY_POOL— Cognito Identity Pool IDAWS_ACCOUNT_ID— AWS account numberCONFIG_MODE— Environment (DEV, QA, PROD)
- One function per directory: Each Lambda function has its own
src/<name>/directory - Shared lib directory: Common code in
lib/is copied into every function's ZIP - Environment from S3: Config and secrets are stored in S3, downloaded at build time, and included in ZIP as
lib/env.py - Swagger-first API design: API Gateway is defined in Swagger YAML, auto-deployed via
aws-apigateway-importer - Local simulation:
run.pymocks Lambda'seventandcontextobjects for local testing - Cognito integration:
connect.pyfetches temporary credentials and signs API requests
Required local setup:
- Python 2.7 (or 3.x if migrated)
- AWS CLI configured with credentials
- S3 bucket for Lambda function storage
- S3 bucket for
.envfile storage
Required AWS resources:
- Lambda execution role (IAM role with permissions for your functions)
- API Gateway (created/updated via Swagger)
- Cognito Identity Pool (if using authenticated APIs)
Environment variables (local development):
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_DEFAULT_REGION— Set viaaws configure
Makefile configuration (hardcoded in Makefile — should be parameterized):
AWS_BUCKET_CODE— S3 bucket for Lambda ZIPsIAM_ROLE— Lambda execution role ARNENV— Environment (DEV, QA, PROD)PROFILE— AWS CLI profile (optional)
First-time setup:
- Create
.envfile with required variables - Upload
.envto S3 at the path expected by Makefile - Update Makefile with correct S3 buckets and IAM role ARNs
- Create Lambda functions:
make create/<function>
Updates:
- Make code changes
- Test locally:
make run/<function> - Deploy:
make deploy/<function>
API Gateway deployment:
- Update Swagger YAML in
swagger/directory - Run
aws-apigateway-importer(see Makefile) - Deploy to stage
Unit tests:
- Write test cases in
tests/test*.py - Each test file can contain multiple test classes
- Import Lambda handlers:
from src.<function>.index import handler - Run:
make test(all) ormake test/<test-name>(specific)
Local integration testing:
- Use
make run/<function> EVENT=events/<test-event>.json - Create test event JSON files for different scenarios
- Verify output matches expected results
API Gateway testing:
- Use
make connect ENDPOINT=/path METHOD=GET QUERY="key=val" - Tests full flow: Cognito auth → API Gateway → Lambda
- Requires Cognito Identity Pool configured
- Python 2.7 is EOL: This framework uses Python 2.7, which is no longer supported. Lambda supports Python 3.9+. Migration recommended.
- Hardcoded S3 buckets: Makefile has hardcoded S3 bucket names and IAM role ARNs. Make these configurable.
- Submodule dependency:
aws-apigateway-importeris a Git submodule. Rungit submodule update --initafter cloning. - lib/ copied into every function: Shared code in
lib/is duplicated in every function's ZIP. For large shared libraries, consider Lambda Layers instead. - Environment secrets in ZIP: The
.envfile is bundled into the function ZIP. For sensitive secrets, use AWS Secrets Manager or Parameter Store instead. - Manual API Gateway deployment: Swagger files must be manually deployed via
aws-apigateway-importer. Consider AWS SAM or Terraform for automated API management. - No Lambda Layers support: This framework predates Lambda Layers. For shared dependencies, use Layers instead of copying
lib/into every ZIP. - Cognito unauthenticated tokens:
connect.pyuses unauthenticated Cognito identities. For authenticated testing, add user pool integration.