{"id":4297,"library":"types-boto3-lambda","title":"Type annotations for boto3 Lambda","description":"Type annotations for boto3 Lambda 1.42.85 service generated with mypy-boto3-builder 8.12.0. This library provides static type checking for AWS Boto3's Lambda client, improving code quality, autocomplete, and error detection in IDEs and with type checkers like Mypy and Pyright. It is part of the `types-boto3` ecosystem, which aims to provide comprehensive type stubs for all Boto3 services. The library typically releases new versions in sync with `boto3` releases.","status":"active","version":"1.42.85","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["boto3","aws","lambda","types","mypy","type-hints","stubs","serverless"],"install":[{"cmd":"pip install 'boto3-stubs[lambda]'","lang":"bash","label":"Recommended installation with boto3-stubs"},{"cmd":"pip install mypy-boto3-lambda","lang":"bash","label":"Standalone package installation"}],"dependencies":[{"reason":"Provides the AWS SDK for Python, for which these are type stubs.","package":"boto3","optional":false},{"reason":"A static type checker that utilizes these type stubs.","package":"mypy","optional":true},{"reason":"A static type checker that utilizes these type stubs.","package":"pyright","optional":true}],"imports":[{"note":"While `boto3.client('lambda')` returns a client, without the explicit import and type annotation, IDEs and type checkers cannot provide full autocompletion or type checking for the client's methods and return values.","wrong":"import boto3; client = boto3.client('lambda')","symbol":"LambdaClient","correct":"from mypy_boto3_lambda.client import LambdaClient"},{"note":"Used for type-hinting the responses from Lambda client methods.","symbol":"InvokeFunctionResponseTypeDef","correct":"from mypy_boto3_lambda.type_defs import InvokeFunctionResponseTypeDef"},{"note":"Used for type-hinting literal values, such as Lambda runtime types.","symbol":"RuntimeType","correct":"from mypy_boto3_lambda.literals import RuntimeType"}],"quickstart":{"code":"import boto3\nimport os\nfrom typing import TYPE_CHECKING\n\nif TYPE_CHECKING:\n    from mypy_boto3_lambda.client import LambdaClient\n    from mypy_boto3_lambda.type_defs import InvokeFunctionResponseTypeDef\n\ndef get_lambda_client() -> \"LambdaClient\":\n    \"\"\"Returns a typed Lambda client.\"\"\"\n    return boto3.client(\"lambda\")\n\ndef invoke_my_lambda(client: \"LambdaClient\", function_name: str, payload: dict) -> \"InvokeFunctionResponseTypeDef\":\n    \"\"\"Invokes a Lambda function with type hints.\"\"\"\n    response = client.invoke(\n        FunctionName=function_name,\n        InvocationType='RequestResponse',\n        Payload=bytes(str(payload).encode('utf-8'))\n    )\n    return response\n\n# Example Usage\nif __name__ == \"__main__\":\n    lambda_client = get_lambda_client()\n    # Use os.environ.get for dynamic configuration in runnable examples\n    function_name = os.environ.get('LAMBDA_FUNCTION_NAME', 'my-test-lambda-function')\n    example_payload = {\"greeting\": \"hello from types-boto3-lambda\"}\n\n    try:\n        print(f\"Invoking Lambda function: {function_name}\")\n        response = invoke_my_lambda(lambda_client, function_name, example_payload)\n        print(f\"Lambda Invocation Status Code: {response.get('StatusCode')}\")\n        # If the Lambda returns a JSON payload, you might want to read and decode it\n        # payload_stream = response.get('Payload')\n        # if payload_stream:\n        #     payload_data = payload_stream.read().decode('utf-8')\n        #     print(f\"Lambda Response Payload: {payload_data}\")\n    except Exception as e:\n        print(f\"Error invoking Lambda: {e}\")","lang":"python","description":"This quickstart demonstrates how to obtain a type-hinted AWS Lambda client and invoke a function. It includes the necessary `TYPE_CHECKING` guard to ensure the type stubs are only used during static analysis, avoiding a runtime dependency. The function name is retrieved from an environment variable for reusability."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and consequently for all generated `types-boto3` packages, including `types-boto3-lambda`.","severity":"breaking","affected_versions":">=8.12.0 (builder), >=1.42.85 (types-boto3-lambda)"},{"fix":"Review and update your TypeDef import paths and names to match the new, shorter conventions.","message":"TypeDef naming conventions changed in `mypy-boto3-builder` version 8.9.0. TypeDefs for packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`).","severity":"breaking","affected_versions":">=8.9.0 (builder), likely versions >=1.35.x (types-boto3-lambda) due to synchronization with boto3"},{"fix":"Always explicitly type annotate your client instances: `client: LambdaClient = boto3.client('lambda')`.","message":"When using `boto3-stubs-lite[lambda]` or `mypy-boto3-lambda` (standalone package), explicit type annotations are often required for `boto3.client` calls to enable full type inference. Without them, IDEs and type checkers might not provide complete suggestions or checks.","severity":"gotcha","affected_versions":"All versions when using lite or standalone packages"},{"fix":"Consider using `boto3-stubs-lite` packages (e.g., `boto3-stubs-lite[lambda]`), disabling PyCharm's built-in type checker in favor of `mypy` or `pyright`, or using explicit type annotations where possible.","message":"PyCharm can experience performance issues with `Literal` overloads in `types-boto3` packages, leading to high CPU usage.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `from typing import TYPE_CHECKING; if TYPE_CHECKING: from mypy_boto3_lambda.client import LambdaClient`.","message":"To avoid `types-boto3-lambda` being a runtime dependency in production code, it is recommended to wrap type imports within a `typing.TYPE_CHECKING` block.","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"}