Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
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".
allowed-tools
Read, Write, Edit, Bash, Glob, Grep
AWS Lambda Python Integration
Patterns for creating high-performance AWS Lambda functions in Python with optimized cold starts and clean architecture.
Overview
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.
When to Use
Use this skill when:
Creating new Lambda functions in Python
Migrating existing Python applications to Lambda
Optimizing cold start performance for Python Lambda
Choosing between framework-based and minimal Python approaches
Configuring API Gateway or ALB integration
Setting up deployment pipelines for Python Lambda
Instructions
1. Choose Your Approach
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
Memory: Start with 256MB for simple handlers, 512MB for complex operations
Timeout: Set based on expected processing time
Simple handlers: 3-5 seconds
API with DB calls: 10-15 seconds
Data processing: 30-60 seconds
Dependencies
Keep requirements.txt minimal:
# 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
Error Handling
Return proper HTTP codes with request ID:
deflambda_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 CloudWatchreturn {'statusCode': 500, 'body': json.dumps({'error': 'Internal error'})}
Validation Checkpoint: Always run serverless print or sam validate before deploying to catch configuration errors early.
Serverless Framework:
# serverless.ymlservice:my-python-apiprovider:name:awsruntime:python3.12# or python3.11functions:api:handler:lambda_function.lambda_handlerevents:-http:path:/{proxy+}method:ANY
AWS SAM:
# template.yamlAWSTemplateFormatVersion:'2010-09-09'Transform:AWS::Serverless-2016-10-31Resources:ApiFunction:Type:AWS::Serverless::FunctionProperties:CodeUri:./Handler:lambda_function.lambda_handlerRuntime:python3.12# or python3.11Events:ApiEvent:Type:ApiProperties:Path:/{proxy+}Method:ANY
AWS Chalice:
chalice 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.
Constraints and Warnings
Lambda Limits
Deployment package: 250MB unzipped maximum (50MB zipped)
Memory: 128MB to 10GB
Timeout: 15 minutes maximum
Concurrent executions: 1000 default (adjustable)
Environment variables: 4KB total size
Python-Specific Considerations
Cold start: Python has excellent cold start performance; avoid heavy imports at module level
Dependencies: Keep requirements.txt minimal; use Lambda Layers for shared dependencies
Native dependencies: Must be compiled for Amazon Linux 2 (x86_64 or arm64)
Common Pitfalls
Importing heavy libraries at module level - Defer to function level if not always needed
Not handling Lambda context - Use context.get_remaining_time_in_millis() for timeout awareness
Not validating input - Always validate and sanitize event data
Printing sensitive data - Be careful with logs and CloudWatch
Error Recovery: If deployment fails, check CloudWatch logs for initialization errors and run sam logs to diagnose issues.
Security Considerations
Never hardcode credentials; use IAM roles and environment variables