/aws-lambda-python-integration
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
$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill aws-lambda-python-integration --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/aws-lambda-python-integration
Context preview
The summary Claude sees to decide when to auto-load this skill.
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
SKILL.md
aws-lambda-python-integration.SKILL.mdname: aws-lambda-python-integration
description: 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 | Low |
2. Project Structure
AWS Chalice Structure
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.pyRaw Python Structure
my-lambda-function/
├── lambda_function.py # Handler entry point
├── requirements.txt # Dependencies
├── template.yaml # SAM/CloudFormation template
└── src/ # Additional modules
├── __init__.py
├── handlers.py
└── utils.py3. Implementation Examples
See the [References](#references) section for detailed implementation guides. Quick examples:
**AWS Chalice:**
from chalice import Chalice
app = Chalice(app_name='my-api')
@app.route('/')
def index():
return {'message': 'Hello from Chalice!'}**Raw Python:**
def lambda_handler(event, context):
return {
'statusCode': 200,
'body': json.dumps({'message': 'Hello from Lambda!'})
}Core Concepts
Cold Start Optimization
Key strategies:
1. **Initialize at module level** - Persists across warm invocations 2. **Use lazy loading** - Defer heavy imports until needed 3. **Cache boto3 clients** - Reuse connections between invocations
See [Raw Python Lambda](references/raw-python-lambda.md#cold-start-optimization) for detailed patterns.
Connection Management
Create clients at module level and reuse:
_dynamodb = None
def get_table():
global _dynamodb
if _dynamodb is None:
_dynamodb = boto3.resource('dynamodb').Table('my-table')
return _dynamodbEnvironment Configuration
class 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")Best Practices
Memory and Timeout Configuration
- **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:
def 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](references/raw-python-lambda.md#error-handling) for structured error patterns.
Logging
Use structured logging for CloudWatch Insights:
import 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](references/raw-python-lambda.md#logging) for advanced patterns.
Deployment Options
Quick Start
> **Validation Checkpoint:** Always run `serverless print` or `sam validate` before deploying to catch configuration errors early.
**Serverless Framework:**
# 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:**
# 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.12Read more
name: aws-lambda-python-integration description: 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 | Low |
2. Project Structure
AWS Chalice Structure
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.pyRaw Python Structure
my-lambda-function/
├── lambda_function.py # Handler entry point
├── requirements.txt # Dependencies
├── template.yaml # SAM/CloudFormation template
└── src/ # Additional modules
├── __init__.py
├── handlers.py
└── utils.py3. Implementation Examples
See the [References](#references) section for detailed implementation guides. Quick examples:
**AWS Chalice:**
from chalice import Chalice
app = Chalice(app_name='my-api')
@app.route('/')
def index():
return {'message': 'Hello from Chalice!'}**Raw Python:**
def lambda_handler(event, context):
return {
'statusCode': 200,
'body': json.dumps({'message': 'Hello from Lambda!'})
}Core Concepts
Cold Start Optimization
Key strategies:
1. **Initialize at module level** - Persists across warm invocations 2. **Use lazy loading** - Defer heavy imports until needed 3. **Cache boto3 clients** - Reuse connections between invocations
See [Raw Python Lambda](references/raw-python-lambda.md#cold-start-optimization) for detailed patterns.
Connection Management
Create clients at module level and reuse:
_dynamodb = None
def get_table():
global _dynamodb
if _dynamodb is None:
_dynamodb = boto3.resource('dynamodb').Table('my-table')
return _dynamodbEnvironment Configuration
class 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")Best Practices
Memory and Timeout Configuration
- **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:
def 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](references/raw-python-lambda.md#error-handling) for structured error patterns.
Logging
Use structured logging for CloudWatch Insights:
import 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](references/raw-python-lambda.md#logging) for advanced patterns.
Deployment Options
Quick Start
> **Validation Checkpoint:** Always run `serverless print` or `sam validate` before deploying to catch configuration errors early.
**Serverless Framework:**
# 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:**
# 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.12Showing the first part of this file.
Modular plugin marketplace for Claude Code and agentic CLIs, with validated, spec-driven skills, agents, commands, and workflows for Java, TypeScript, Python, PHP, AWS, and AI.
Repo: giuseppe-trisciuoglio/developer-kit
Other skills on developer-kit.
- /chunking-strategy
Provides chunking strategies for RAG systems. Generates chunk size recommendations (256-1024 tokens), overlap percentages (10-20%), and semantic boundary detection methods. Validates semantic coherence and evaluates retrieval precision/recall metrics. Use when building
Open skill - /prompt-engineering
Provides workflows to write, debug, and optimize prompts for LLMs, including few-shot example selection, chain-of-thought structuring, system prompt design, and template composition. Use when the user asks to write or improve a prompt, wants help with few-shot examples,
Open skill - /rag
Implements document chunking, embedding generation, vector storage, and retrieval pipelines for Retrieval-Augmented Generation systems. Use when building RAG applications, creating document Q&A systems, or integrating AI with knowledge bases.
Open skill - /aws-cloudformation-auto-scaling
Provides AWS CloudFormation patterns for Auto Scaling including EC2, ECS, and Lambda. Use when creating Auto Scaling groups, launch configurations, launch templates, scaling policies, lifecycle hooks, and predictive scaling. Covers template structure with Parameters, Outputs,
Open skill - /aws-cloudformation-bedrock
Provides AWS CloudFormation patterns for Amazon Bedrock resources including agents, knowledge bases, data sources, guardrails, prompts, flows, and inference profiles. Use when creating Bedrock agents with action groups, implementing RAG with knowledge bases, configuring vector
Open skill - /aws-cloudformation-cloudfront
Provides AWS CloudFormation patterns for CloudFront distributions, origins (ALB, S3, Lambda@Edge, VPC Origins), CacheBehaviors, Functions, SecurityHeaders, parameters, Outputs and cross-stack references. Use when creating CloudFront distributions with CloudFormation, configuring
Open skill

