cursor-rules / rules
Cursor rule8 starsChanged 19 months agoMITView on GitHub
AWS Lambda Function Best Practices
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository17 other files it gives its agents.
- .cursor/rules/aws-bedrock.mdcCursor rule
- .cursor/rules/aws-cloudformation.mdcCursor rule
- .cursor/rules/aws-dynamodb.mdcCursor rule
- .cursor/rules/aws-eventbridge.mdcCursor rule
- .cursor/rules/aws-gamelift.mdcCursor rule
- .cursor/rules/aws-iam.mdcCursor rule
- .cursor/rules/aws-sagemaker.mdcCursor rule
- .cursor/rules/aws-sam.mdcCursor rule
- .cursor/rules/aws-vpc.mdcCursor rule
- .cursor/rules/base.mdcCursor rule
- .cursor/rules/docs-structure.mdcCursor rule
- .cursor/rules/expo.mdcCursor rule
- .cursor/rules/nextjs.mdcCursor rule
- .cursor/rules/react.mdcCursor rule
- .cursor/rules/react-native.mdcCursor rule
- .cursor/rules/readme-documentation.mdcCursor rule
- .cursor/rules/typescript.mdcCursor rule
The file
Show its rules and text
We split this aws-lambda.mdc into the rules it gives an agent
35 rules. About 0 are common, 35 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈35
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Follow single responsibility principle for each Lambda function
- Distinctive: line 17
Keep functions focused on one specific task or domain operation
- Distinctive: line 19
Create pure functions where possible for easier testing
- Distinctive: line 22
Avoid long-running processes.
- Distinctive: line 25
Keep handlers thin, delegating to service or business logic layers
- Distinctive: line 28
Add custom context to errors for better debugging
- Distinctive: line 29
Follow these layers in Lambda implementation:
- Distinctive: line 41
Use environment variables for configuration
- Distinctive: line 46
Keep function code and dependencies lightweight
- Distinctive: line 47
Use AWS Lambda Layers for large dependencies
- Distinctive: line 48
Use provisioned concurrency for critical paths
- Distinctive: line 50
Consider using NodeJS or native runtime for faster cold starts
- Distinctive: line 56
Add context information to errors
- Distinctive: line 57
Use structured logging with correlation IDs
- Distinctive: line 59
Use try/catch blocks with specific error types
- Distinctive: line 61
Consider implementing circuit breakers for external services
- Distinctive: line 65
Never store secrets in environment variables - use Parameter Store or Secrets Manager
- Distinctive: line 68
Use Enhanced VPC Flow Logs with Lambda in VPC
- Distinctive: line 70
Use AWS X-Ray for tracing
- Distinctive: line 76
Use async patterns for non-critical operations
- Distinctive: line 79
Consider using provisioned concurrency vs.
- Distinctive: line 81
Use Step Functions for complex workflows instead of long-running Lambdas
- Distinctive: line 85
Add correlation IDs across service invocations
- Distinctive: line 86
Use CloudWatch metrics for monitoring key performance indicators
- Distinctive: line 90
Create custom metrics for business-specific monitoring
- Distinctive: line 95
Use Parameter Store for more complex configuration
- Distinctive: line 99
Write unit tests for business logic
- Distinctive: line 100
Create integration tests for service interactions
- Distinctive: line 102
Use mocks for AWS services in unit tests
- Distinctive: line 103
Test error handling and edge cases
- Distinctive: line 105
Create test fixtures for common test data
- Distinctive: line 108
Use Infrastructure as Code (CloudFormation, SAM, CDK)
- Distinctive: line 110
Use function versions and aliases for controlled deployments
- Distinctive: line 113
Create separate stacks for different environments
- Distinctive: line 114
Consider using SAM for simplified Lambda deployment
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
--- description: AWS Lambda Function Best Practices globs: alwaysApply: false --- --- Description: AWS Lambda Function Best Practices Globs: **/lambda/**/*.ts, **/functions/**/*.ts, **/src/**/*.ts, **/lambda/**/*.py, **/functions/**/*.py, **/src/**/*.py --- # AWS Lambda Development Standards @base.mdc @typescript.mdc ## Lambda Function Design - Follow single responsibility principle for each Lambda function - Keep functions focused on one specific task or domain operation - Separate business logic from infrastructure concerns - Create pure functions where possible for easier testing - Implement idempotent functions to handle retries safely - Design functions to be stateless - Avoid long-running processes; break them into smaller steps ## Handler Structure - Keep handlers thin, delegating to service or business logic layers - Validate input parameters early in the function - Return properly structured responses - Add custom context to errors for better debugging - Follow these layers in Lambda implementation: 1. Handler layer (entry point) 2. Service layer (business logic) 3. Data access layer (repository pattern) 4. External service integrations ## Performance Optimization - Initialize SDK clients and database connections outside the handler - Cache static assets and reference data between invocations - Implement connection pooling for database access - Utilize provisioned concurrency for latency-sensitive functions - Set appropriate memory allocation based on function needs - Use environment variables for configuration - Implement backoff strategies for external service calls - Leverage AWS SDK client reuse whenever possible ## Cold Start Mitigation - Keep function code and dependencies lightweight - Use AWS Lambda Layers for large dependencies - Use provisioned concurrency for critical paths - Implement warmup mechanisms for important functions - Consider using NodeJS or native runtime for faster cold starts - Choose appropriate memory settings to balance CPU/memory needs - Set reasonable function timeouts ## Error Handling - Implement comprehensive error handling and logging - Add context information to errors - Use structured logging with correlation IDs - Distinguish between client errors (4xx) and server errors (5xx) - Use try/catch blocks with specific error types - Handle retries with exponential backoff - Consider implementing circuit breakers for external services ## Security Best Practices - Apply least privilege principle to Lambda IAM roles - Never store secrets in environment variables - use Parameter Store or Secrets Manager - Implement input validation for all parameters - Set environment variables for configuration - Use Enhanced VPC Flow Logs with Lambda in VPC - Enable Lambda Insights for monitoring - Use AWS X-Ray for tracing - Implement rate limiting for public-facing functions ## Cost Optimization - Optimize memory allocation for the workload - Implement aggressive timeouts - Use async patterns for non-critical operations - Batch operations where possible - Minimize dependency size to reduce execution time - Consider using provisioned concurrency vs. on-demand based on traffic patterns - Optimize code and dependencies to reduce execution time - Use Step Functions for complex workflows instead of long-running Lambdas ## Observability - Implement structured logging with consistent formats - Add correlation IDs across service invocations - Use CloudWatch metrics for monitoring key performance indicators - Set up alerts for errors, throttling, and timeout events - Enable X-Ray tracing for complex operations - Log important business events and metrics - Create custom metrics for business-specific monitoring ## Environment-Specific Configuration - Use environment variables for configuration - Implement feature flags for controlled releases - Use Parameter Store for more complex configuration - Implement different logging levels based on environment ## Testing Guidelines - Write unit tests for business logic - Create integration tests for service interactions - Implement local testing with aws-sam-local or localstack - Use mocks for AWS services in unit tests - Test error handling and edge cases - Validate retry and backoff strategies - Create test fixtures for common test data ## Deployment Practices - Use Infrastructure as Code (CloudFormation, SAM, CDK) - Implement CI/CD pipelines for automated deployment - Use function versions and aliases for controlled deployments - Implement progressive deployment strategies (canary, blue/green) - Automate rollback procedures - Create separate stacks for different environments - Consider using SAM for simplified Lambda deployment
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

