Marketplace

aws-lambda-functions

Build optimized serverless functions with Lambda

$ Installer

git clone https://github.com/pluginagentmarketplace/custom-plugin-aws /tmp/custom-plugin-aws && cp -r /tmp/custom-plugin-aws/skills/aws-lambda-functions ~/.claude/skills/custom-plugin-aws

// tip: Run this command in your terminal to install the skill


name: aws-lambda-functions description: Build optimized serverless functions with Lambda sasmp_version: "1.3.0" bonded_agent: 07-aws-serverless bond_type: PRIMARY_BOND

AWS Lambda Functions Skill

Develop high-performance serverless functions with best practices.

Quick Reference

AttributeValue
AWS ServiceLambda
ComplexityMedium
Est. Time5-15 min
PrerequisitesIAM Role, (Optional) VPC

Parameters

Required

ParameterTypeDescriptionValidation
function_namestringFunction name^[a-zA-Z0-9-_]{1,64}$
runtimestringRuntime environmentpython3.12, nodejs20.x, etc.
handlerstringHandler functionmodule.function
role_arnstringExecution role ARNValid IAM role ARN

Optional

ParameterTypeDefaultDescription
memory_mbint128Memory allocation (128-10240)
timeoutint3Timeout seconds (1-900)
architecturestringx86_64x86_64 or arm64
environmentobject{}Environment variables
vpc_configobjectnullVPC configuration

Execution Flow

1. Package code and dependencies
2. Create/update function
3. Configure triggers
4. Set concurrency limits
5. Test invocation
6. Monitor cold starts

Implementation

Create Function

# Create deployment package
zip -r function.zip . -x "*.git*"

# Create function
aws lambda create-function \
  --function-name my-function \
  --runtime python3.12 \
  --architectures arm64 \
  --handler main.handler \
  --role arn:aws:iam::123456789012:role/lambda-role \
  --zip-file fileb://function.zip \
  --memory-size 1024 \
  --timeout 30 \
  --environment "Variables={LOG_LEVEL=INFO}" \
  --tracing-config Mode=Active

Handler Template (Python)

import json
import logging

logger = logging.getLogger()
logger.setLevel(logging.INFO)

def handler(event, context):
    """
    Lambda handler function.

    Args:
        event: Trigger event data
        context: Runtime context (request_id, memory_limit, etc.)

    Returns:
        Response object or value
    """
    try:
        logger.info(f"Event: {json.dumps(event)}")

        # Business logic here
        result = process_event(event)

        return {
            "statusCode": 200,
            "body": json.dumps(result)
        }
    except Exception as e:
        logger.error(f"Error: {str(e)}")
        return {
            "statusCode": 500,
            "body": json.dumps({"error": str(e)})
        }

Handler Template (Node.js)

export const handler = async (event, context) => {
    console.log('Event:', JSON.stringify(event));

    try {
        const result = await processEvent(event);

        return {
            statusCode: 200,
            body: JSON.stringify(result)
        };
    } catch (error) {
        console.error('Error:', error);
        return {
            statusCode: 500,
            body: JSON.stringify({ error: error.message })
        };
    }
};

Memory/CPU Optimization

MemoryvCPUNetworkUse Case
128 MB0.08LowSimple transforms
512 MB0.33LowBasic API handlers
1024 MB0.58MediumStandard workloads
1769 MB1.0MediumCPU-bound tasks
3008 MB2.0HighParallel processing
10240 MB6.0Very HighData processing

Cold Start Mitigation

  1. Use arm64: ~34% better price-performance
  2. Minimize package: Only required dependencies
  3. Use Layers: Shared dependencies
  4. Provisioned Concurrency: Pre-warmed functions
  5. SnapStart (Java): Cached initialization
  6. Avoid VPC: Unless necessary (+1s cold start)

Troubleshooting

Common Issues

SymptomCauseSolution
TimeoutLong executionIncrease timeout, optimize code
OOM (signal: killed)Memory exceededIncrease memory
Import errorMissing dependencyCheck package includes deps
Permission deniedIAM roleUpdate execution role

Debug Checklist

  • Handler path correct (file.function)?
  • All dependencies packaged?
  • Execution role has permissions?
  • Environment variables set?
  • Memory sufficient for workload?
  • Timeout appropriate?
  • VPC has NAT for internet?

CloudWatch Log Patterns

Task timed out after X.XX seconds → Increase timeout
Runtime exited with error: signal: killed → Increase memory
Unable to import module → Check handler path/dependencies
ECONNREFUSED → Check VPC/security group

Test Template

def test_lambda_handler():
    # Arrange
    event = {"key": "value"}
    context = MockContext()

    # Act
    response = handler(event, context)

    # Assert
    assert response["statusCode"] == 200
    body = json.loads(response["body"])
    assert "result" in body

Observability

X-Ray Tracing

from aws_xray_sdk.core import xray_recorder

@xray_recorder.capture('process_data')
def process_data(data):
    # Traced function
    pass

Structured Logging

{
  "level": "INFO",
  "message": "Processing request",
  "request_id": "abc-123",
  "function_name": "my-function",
  "cold_start": true
}

Assets

  • assets/lambda-template.py - Python handler template

References