{"id":3409,"library":"aws-lambda-typing","title":"AWS Lambda Typing","description":"A Python package providing comprehensive type hints for AWS Lambda event, context, and response objects. It enhances developer experience with IDE autocomplete and static type checking, without runtime impact. The library is actively maintained with frequent updates to support new Lambda event structures.","status":"active","version":"2.20.0","language":"en","source_language":"en","source_url":"https://github.com/MousaZeidBaker/aws-lambda-typing","tags":["AWS","Lambda","typing","type hints","serverless","Mypy","static analysis"],"install":[{"cmd":"pip install aws-lambda-typing","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"Context","correct":"from aws_lambda_typing.context import Context"},{"symbol":"APIGatewayProxyEventV2","correct":"from aws_lambda_typing.events.api_gateway import APIGatewayProxyEventV2"},{"symbol":"SQSEvent","correct":"from aws_lambda_typing.events.sqs import SQSEvent"},{"symbol":"APIGatewayProxyResponseV2","correct":"from aws_lambda_typing.responses.api_gateway import APIGatewayProxyResponseV2"},{"note":"While older versions might have allowed direct import from `events`, specific event types are now organized into submodules for better clarity and maintainability.","wrong":"from aws_lambda_typing.events import APIGatewayProxyEventV1","symbol":"APIGatewayProxyEventV1","correct":"from aws_lambda_typing.events.api_gateway import APIGatewayProxyEventV1"}],"quickstart":{"code":"import os\nfrom aws_lambda_typing.context import Context\nfrom aws_lambda_typing.events.api_gateway import APIGatewayProxyEventV2\nfrom aws_lambda_typing.responses.api_gateway import APIGatewayProxyResponseV2\n\ndef lambda_handler(\n    event: APIGatewayProxyEventV2,\n    context: Context\n) -> APIGatewayProxyResponseV2:\n    path = event.get('requestContext', {}).get('http', {}).get('path', '/')\n    method = event.get('requestContext', {}).get('http', {}).get('method', 'GET')\n    query_params = event.get('queryStringParameters', {})\n\n    print(f\"Received {method} request for {path} with query params: {query_params}\")\n\n    # Example of accessing context object\n    print(f\"Lambda function name: {context.function_name}\")\n\n    return {\n        'statusCode': 200,\n        'headers': {'Content-Type': 'application/json'},\n        'body': '{\"message\": \"Hello from typed Lambda!\"}'\n    }","lang":"python","description":"This quickstart demonstrates a basic AWS Lambda handler using type hints for an API Gateway HTTP API (v2) event and context object, and specifies the expected response type. It illustrates how to access common event fields and context attributes with IDE assistance."},"warnings":[{"fix":"Upgrade to `aws-lambda-typing` version 2.17.1 or newer. For older versions, manually annotate potentially missing fields as `Optional[type]`.","message":"Older versions of `aws-lambda-typing` (prior to 2.17.1) might have incorrectly marked all fields in `APIGatewayProxyResponseV1` as required due to default `TypedDict` behavior, leading to static analysis errors if optional fields were omitted. Similarly, API Gateway event fields were made `Optional` in v2.16.4.","severity":"gotcha","affected_versions":"<2.17.1"},{"fix":"Regularly update `aws-lambda-typing` to its latest version to ensure compatibility with the most current AWS Lambda event schemas. Consult the GitHub releases for changes related to specific event types.","message":"The structure of AWS Lambda event objects frequently evolves. Using an outdated version of `aws-lambda-typing` may lead to missing or incorrect type definitions for newer event structures, causing type checker warnings or runtime `KeyError` if types are used for validation.","severity":"gotcha","affected_versions":"All versions (if not kept up-to-date)"},{"fix":"Use dedicated typing solutions like `types-boto3` or generate service-specific types for `boto3` responses if strict type checking is desired for AWS SDK interactions within your Lambda functions. Keep a clear separation between event/context types and service client response types.","message":"While `aws-lambda-typing` provides robust types for Lambda events and context, it does not include types for `boto3` service responses. Mixing `boto3` response structures directly with `aws-lambda-typing` event types can lead to type mismatches.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}