Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Provides AWS Lambda integration patterns for Python with cold start optimization. Use when deploying Python functions to AWS Lambda, choosing between AWS Chalice and raw Python approaches, optimizing cold starts, configuring API Gateway or ALB integration, or implementing serverless Python applications. Triggers include "create lambda python", "deploy python lambda", "chalice lambda aws", "python lambda cold start", "aws lambda python performance", "python serverless framework".
.claude/skills/giuseppe-trisciuoglio-aws-lambda-python-integration/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 48% | 0% |
| case-01 | ✗→✓ | ▲ Improved | 71% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 105% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 20% | 0% |
| case-18 | ✗→✓ | ▲ Improved | 250% | 0% |
Patterns for creating high-performance AWS Lambda functions in Python with optimized cold starts and clean architecture.
AWS Lambda Python integration with two approaches: AWS Chalice (full-featured framework) and Raw Python (minimal overhead). Both support API Gateway/ALB integration with production-ready configurations.
Use this skill when:
| Approach | Cold Start | Best For | Complexity | |----------|------------|----------|------------| | AWS Chalice | < 200ms | REST APIs, rapid development, built-in routing | Low | | Raw Python | < 100ms | Simple handlers, maximum control, minimal dependencies | Low |
my-chalice-app/
├── app.py # Main application with routes
├── requirements.txt # Dependencies
├── .chalice/
│ ├── config.json # Chalice configuration
│ └── deploy/ # Deployment artifacts
├── chalicelib/ # Additional modules
│ ├── __init__.py
│ └── services.py
└── tests/
└── test_app.pymy-lambda-function/
├── lambda_function.py # Handler entry point
├── requirements.txt # Dependencies
├── template.yaml # SAM/CloudFormation template
└── src/ # Additional modules
├── __init__.py
├── handlers.py
└── utils.pySee the References section for detailed implementation guides. Quick examples:
AWS Chalice:
pythonfrom chalice import Chalice app = Chalice(app_name='my-api') @app.route('/') def index(): return {'message': 'Hello from Chalice!'}
Raw Python:
pythondef lambda_handler(event, context): return { 'statusCode': 200, 'body': json.dumps({'message': 'Hello from Lambda!'}) }
Key strategies:
See Raw Python Lambda for detailed patterns.
Create clients at module level and reuse:
python_dynamodb = None def get_table(): global _dynamodb if _dynamodb is None: _dynamodb = boto3.resource('dynamodb').Table('my-table') return _dynamodb
pythonclass Config: TABLE_NAME = os.environ.get('TABLE_NAME') DEBUG = os.environ.get('DEBUG', 'false').lower() == 'true' @classmethod def validate(cls): if not cls.TABLE_NAME: raise ValueError("TABLE_NAME required")
Keep requirements.txt minimal:
txt# Core AWS SDK - always needed boto3>=1.35.0 # Only add what you need requests>=2.32.0 # If calling external APIs pydantic>=2.5.0 # If using data validation
Return proper HTTP codes with request ID:
pythondef lambda_handler(event, context): try: result = process_event(event) return {'statusCode': 200, 'body': json.dumps(result)} except ValueError as e: return {'statusCode': 400, 'body': json.dumps({'error': str(e)})} except Exception as e: print(f"Error: {str(e)}") # Log to CloudWatch return {'statusCode': 500, 'body': json.dumps({'error': 'Internal error'})}
See Raw Python Lambda for structured error patterns.
Use structured logging for CloudWatch Insights:
pythonimport logging, json logger = logging.getLogger() logger.setLevel(logging.INFO) # Structured log logger.info(json.dumps({ 'eventType': 'REQUEST', 'requestId': context.aws_request_id, 'path': event.get('path') }))
See Raw Python Lambda for advanced patterns.
> Validation Checkpoint: Always run serverless print or sam validate before deploying to catch configuration errors early.
Serverless Framework:
yaml# serverless.yml service: my-python-api provider: name: aws runtime: python3.12 # or python3.11 functions: api: handler: lambda_function.lambda_handler events: - http: path: /{proxy+} method: ANY
AWS SAM:
yaml# template.yaml AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: ApiFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./ Handler: lambda_function.lambda_handler Runtime: python3.12 # or python3.11 Events: ApiEvent: Type: Api Properties: Path: /{proxy+} Method: ANY
AWS Chalice:
bashchalice new-project my-api cd my-api chalice local 8080 # Test locally before deploying chalice deploy --stage dev
> Validation Checkpoint: Test locally with chalice local or sam local invoke before deploying to production.
For complete deployment configurations including CI/CD, environment-specific settings, and advanced SAM/Serverless patterns, see Serverless Deployment.
requirements.txt minimal; use Lambda Layers for shared dependenciescontext.get_remaining_time_in_millis() for timeout awarenessError Recovery: If deployment fails, check CloudWatch logs for initialization errors and run sam logs to diagnose issues.
For detailed guidance on specific topics:
Input:
Create a Python Lambda REST API using AWS Chalice for a todo applicationProcess:
chalice new-projectchalice deployOutput:
Input:
My Python Lambda has slow cold start, how do I optimize it?Process:
Output:
Input:
Configure CI/CD for Python Lambda with SAMProcess:
Output:
.github/workflows/deploy.ymlVersion: 1.0.0
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-02 | fail→pass | 16,250 | 10,746 | -34% | 1 | 1 | 0% | 2,905 | 4,285 | +48% | 0 | 0 | — |
case-01 | fail→pass | 16,130 | 15,312 | -5% | 1 | 1 | 0% | 3,151 | 5,381 | +71% | 0 | 0 | — |
case-03 | fail→pass | 13,831 | 11,757 | -15% | 1 | 1 | 0% | 2,061 | 4,232 | +105% | 0 | 0 | — |
case-04 | pass→pass | 12,205 | 8,469 | -31% | 1 | 1 | 0% | 2,137 | 3,603 | +69% | 0 | 0 | — |
case-05 | fail→fail | 12,355 | 7,018 | -43% | 1 | 1 | 0% | 2,049 | 3,488 | +70% | 0 | 0 | — |
case-06 | fail→pass | 16,751 | 4,682 | -72% | 1 | 1 | 0% | 2,534 | 3,030 | +20% | 0 | 0 | — |
case-07 | pass→pass | 12,631 | 10,133 | -20% | 1 | 1 | 0% | 2,250 | 4,160 | +85% | 0 | 0 | — |
case-12 | fail→fail | 12,147 | 20,209 | +66% | 1 | 1 | 0% | 2,311 | 4,247 | +84% | 0 | 0 | — |
case-08 | pass→pass | 11,676 | 7,016 | -40% | 1 | 1 | 0% | 2,091 | 3,497 | +67% | 0 | 0 | — |
case-09 | pass→pass | 12,424 | 8,509 | -32% | 1 | 1 | 0% | 2,079 | 3,772 | +81% | 0 | 0 | — |
case-10 | pass→pass | 4,014 | 3,038 | -24% | 1 | 1 | 0% | 608 | 2,762 | +354% | 0 | 0 | — |
case-11 | pass→pass | 9,391 | 8,815 | -6% | 1 | 1 | 0% | 1,633 | 4,033 | +147% | 0 | 0 | — |
case-13 | fail→fail | 43,365 | 15,864 | -63% | 1 | 1 | 0% | 3,062 | 5,690 | +86% | 0 | 0 | — |
case-14 | pass→pass | 9,353 | 8,422 | -10% | 1 | 1 | 0% | 1,681 | 3,821 | +127% | 0 | 0 | — |
case-15 | pass→pass | 11,280 | 6,900 | -39% | 1 | 1 | 0% | 2,278 | 3,547 | +56% | 0 | 0 | — |
case-16 | pass→pass | 17,606 | 10,259 | -42% | 1 | 1 | 0% | 2,138 | 4,048 | +89% | 0 | 0 | — |
case-17 | pass→pass | 8,054 | 2,836 | -65% | 1 | 1 | 0% | 1,406 | 2,816 | +100% | 0 | 0 | — |
case-18 | fail→pass | 5,038 | 4,477 | -11% | 1 | 1 | 0% | 905 | 3,166 | +250% | 0 | 0 | — |
case-19 | pass→pass | 7,589 | 2,810 | -63% | 1 | 1 | 0% | 1,209 | 2,793 | +131% | 0 | 0 | — |
case-20 | pass→pass | 19,533 | 14,242 | -27% | 1 | 1 | 0% | 3,398 | 4,833 | +42% | 0 | 0 | — |
case-21 | pass→pass | 19,205 | 17,232 | -10% | 1 | 1 | 0% | 3,204 | 5,455 | +70% | 0 | 0 | — |
case-22 | pass→pass | 11,412 | 10,778 | -6% | 1 | 1 | 0% | 2,406 | 4,556 | +89% | 0 | 0 | — |
case-23 | pass→pass | 11,282 | 4,333 | -62% | 1 | 1 | 0% | 1,813 | 2,929 | +62% | 0 | 0 | — |
case-24 | fail→pass | 15,538 | 11,956 | -23% | 1 | 1 | 0% | 2,497 | 4,586 | +84% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 24 cases were attempted. The headline lift of +25 percentage points is the difference between those two pass rates over the 24 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.