AIBS Informatics AWS Lambda¶
Overview¶
This is a base package that can be used standalone with some core lambda functionality or as a dependency. It contains several classes and functions that make it easy to create strongly typed lambda functions with many nice-to-have features including:
- Serialization/deserialization
- Easy metrics integration
- Utilities for batch SQS and DynamoDB event bridge processing
- Collection of general purpose lambda handler classes
Features¶
Base Classes¶
| Class | Description |
|---|---|
LambdaHandler |
Base class for creating strongly typed lambda functions |
ApiLambdaHandler |
Base class for API Gateway handlers |
ApiResolverBuilder |
Utility class for building API Gateway resolvers |
Standalone Lambda Handlers¶
AWS Batch¶
CreateDefinitionAndPrepareArgsHandler- Handles creation and preparation of AWS Batch job definitions
Data Sync¶
GetJSONFromFileHandler- Retrieves JSON data from a filePutJSONToFileHandler- Writes JSON data to a fileDataSyncHandler- Simple data sync taskBatchDataSyncHandler- Handles batch of data sync tasksPrepareBatchDataSyncHandler- Prepares data synchronization for AWS BatchGetDataPathStatsHandler- Retrieves statistics about data pathsListDataPathsHandler- Lists data pathsOutdatedDataPathScannerHandler- Scans for outdated data pathsRemoveDataPathsHandler- Removes data paths
Demand Execution¶
PrepareDemandScaffoldingHandler- Prepares scaffolding for demand execution
Notifications¶
NotificationRouter- Routes notifications to appropriate notifierSESNotifier- Sends notifications via Amazon SESSNSNotifier- Sends notifications via Amazon SNS
ECR¶
ImageReplicatorHandler- Handles replication of ECR images between repositories
Quick Start¶
Installation¶
pip install aibs-informatics-aws-lambda
Basic Usage¶
from dataclasses import dataclass
from aibs_informatics_core.models.base import SchemaModel
from aibs_informatics_aws_lambda.common.handler import LambdaHandler
@dataclass
class MyRequest(SchemaModel):
name: str
@dataclass
class MyResponse(SchemaModel):
message: str
class MyHandler(LambdaHandler[MyRequest, MyResponse]):
def handle(self, request: MyRequest) -> MyResponse:
return MyResponse(message=f"Hello, {request.name}!")
# Create handler function for AWS Lambda
handler = MyHandler.get_handler()
CLI Invocation¶
handle-lambda-request \
--handler-qualified-name aibs_informatics_aws_lambda.handlers.data_sync.operations.GetJSONFromFileHandler \
--payload '{"path": "/path/to/file.json"}' \
--response-location /tmp/response.json
Contributing¶
Any and all PRs are welcome. Please see CONTRIBUTING.md for more information.
License¶
This software is licensed under the Allen Institute Software License. For more information, please visit Allen Institute Terms of Use.