Registry / type-stubs / aws-lambda-typing

aws-lambda-typing

JSON →
library2.20.0pypypi✓ verified 22d ago

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.

pip install aws-lambda-typing
INSTALL
IMPORT
SIG · AWS-LAMBDA-TYPING
A
aws-lambda-typing
type-stubspythonv2.20.0
Install
1.5s avg
Import
11ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.20.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.012s · 18.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.006s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Context
from aws_lambda_typing.context import Context
APIGatewayProxyEventV2
from aws_lambda_typing.events.api_gateway import APIGatewayProxyEventV2
SQSEvent
from aws_lambda_typing.events.sqs import SQSEvent
APIGatewayProxyResponseV2
from aws_lambda_typing.responses.api_gateway import APIGatewayProxyResponseV2
APIGatewayProxyEventV1
from aws_lambda_typing.events.api_gateway import APIGatewayProxyEventV1
from aws_lambda_typing.events import APIGatewayProxyEventV1
While older versions might have allowed direct import from `events`, specific event types are now organized into submodules for better clarity and maintainability.

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.

import os from aws_lambda_typing.context import Context from aws_lambda_typing.events.api_gateway import APIGatewayProxyEventV2 from aws_lambda_typing.responses.api_gateway import APIGatewayProxyResponseV2 def lambda_handler( event: APIGatewayProxyEventV2, context: Context ) -> APIGatewayProxyResponseV2: path = event.get('requestContext', {}).get('http', {}).get('path', '/') method = event.get('requestContext', {}).get('http', {}).get('method', 'GET') query_params = event.get('queryStringParameters', {}) print(f"Received {method} request for {path} with query params: {query_params}") # Example of accessing context object print(f"Lambda function name: {context.function_name}") return { 'statusCode': 200, 'headers': {'Content-Type': 'application/json'}, 'body': '{"message": "Hello from typed Lambda!"}' }
Debug
Known issues
gotchaOlder 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.
fix
Upgrade to `aws-lambda-typing` version 2.17.1 or newer. For older versions, manually annotate potentially missing fields as `Optional[type]`.
affects: <2.17.1
gotchaThe 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.
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.
affects: All versions (if not kept up-to-date)
gotchaWhile `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.
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'aws_lambda_typing'
The 'aws-lambda-typing' package is not installed in the environment.
fix
Install the package using pip: 'pip install aws-lambda-typing'.
ImportError: cannot import name 'LambdaContext' from 'aws_lambda_typing'
The import statement is incorrect or the package version does not include 'LambdaContext'.
fix
Ensure the correct import statement: 'from aws_lambda_typing import LambdaContext'.
TypeError: 'LambdaContext' object is not callable
Attempting to call 'LambdaContext' as a function instead of using it as a type hint.
fix
Use 'LambdaContext' as a type hint in function definitions, not as a callable.
AttributeError: module 'aws_lambda_typing' has no attribute 'APIGatewayProxyEvent'
The 'APIGatewayProxyEvent' class is not present in the 'aws_lambda_typing' module.
fix
Verify the package documentation for the correct class name or update to the latest version.
NameError: name 'LambdaContext' is not defined
The 'LambdaContext' class has not been imported or is misspelled.
fix
Ensure the correct import statement: 'from aws_lambda_typing import LambdaContext'.
Upgrade
Version history
2.20.0latest on PyPI · released Apr 2, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
51 hits · last 30 days
node
44
OpenAI (training)
1
Resources
aws-lambda-typing — pip install aws-lambda-typing · libregistry