Skip to content

Commit b654ca6

Browse files
feat(trigger): data class and helper functions for lambda trigger events (#159)
* feat(trigger): class wrapper for events Put together an intial set of common lambda trigger events * build: fix build for python 3.6 * fix(linters): make the python linters happy * tests: add missing test cases * docs: Include some docstrings Tracked down some of the AWS docs to inline with the dict wrapper classes. * feat(trigger): initial cognito triggers * feat(trigger): add event_bridge_event * feat(trigger): use consistent getter name For cases when the dict name conflicts with a python builtin we should use a consistent method name * refactor: less copies passed around * feat(trigger): add UserMigrationTriggerEvent Add support for UserMigrationTriggerEvent and include better docstrings * feat(trigger): cognito custom message and pre-auth Add support for CustomMessageTriggerEvent and PreAuthenticationTriggerEvent * feat(trigger): cognito pre token and post auth Add support for PreTokenGenerationTriggerEvent and PostAuthenticationTriggerEvent * tests(trigger): some extra checks * chore(trigger): clean up and docs Changes: * Add some missing docs pull for various AWS Docs * Fix SQS mapping * Make docs consistent * chore: consistent naming * feat(trigger): Add api gateway proxy events * chore: Add more docs * fix(trigger): better type hinting * feat(trigger): Add conveince methods For both SNS and S3 event notifications we actually include a single records, so we can have conveince metods to access popular resources * feat(trigger): Create DictWrapper Use new DictWrapper abstract class for the data classes that wrap an event Dict * feat(trigger): API gateway helper methods * feat(trigger): Kinesis stream event Add support for Kinesis stream events with a helper method to decode data * feat(trigger): Application load balancer event Create BaseProxyEvent for some reusable code for the http proxy events Add support for ALB events * refactor(trigger): Split decompress and parse For handling CloudWatchLogsEvent log data split the Decode and decompress from the parse as CloudWatchLogsDecodedData * feat(trigger): Some attribte caching * fix(trigger): Init with __init__ * fix(trigger): Add missing __eq__ We don't need to include `_decompressed_logs_data` and `_json_logs_data` in equality tests * feat(trigger): unquote_plus s3 object key * refactor(data_classes): rename package from trigger * refactor(data_classes): Use DictWrapper consistently
1 parent a25e3b1 commit b654ca6

32 files changed

+3497
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from .alb_event import ALBEvent
2+
from .api_gateway_proxy_event import APIGatewayProxyEvent, APIGatewayProxyEventV2
3+
from .cloud_watch_logs_event import CloudWatchLogsEvent
4+
from .dynamo_db_stream_event import DynamoDBStreamEvent
5+
from .event_bridge_event import EventBridgeEvent
6+
from .kinesis_stream_event import KinesisStreamEvent
7+
from .s3_event import S3Event
8+
from .ses_event import SESEvent
9+
from .sns_event import SNSEvent
10+
from .sqs_event import SQSEvent
11+
12+
__all__ = [
13+
"APIGatewayProxyEvent",
14+
"APIGatewayProxyEventV2",
15+
"ALBEvent",
16+
"CloudWatchLogsEvent",
17+
"DynamoDBStreamEvent",
18+
"EventBridgeEvent",
19+
"KinesisStreamEvent",
20+
"S3Event",
21+
"SESEvent",
22+
"SNSEvent",
23+
"SQSEvent",
24+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Dict, List, Optional
2+
3+
from aws_lambda_powertools.utilities.data_classes.common import BaseProxyEvent, DictWrapper
4+
5+
6+
class ALBEventRequestContext(DictWrapper):
7+
@property
8+
def elb_target_group_arn(self) -> str:
9+
return self["requestContext"]["elb"]["targetGroupArn"]
10+
11+
12+
class ALBEvent(BaseProxyEvent):
13+
"""Application load balancer event
14+
15+
Documentation:
16+
--------------
17+
- https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html
18+
"""
19+
20+
@property
21+
def request_context(self) -> ALBEventRequestContext:
22+
return ALBEventRequestContext(self)
23+
24+
@property
25+
def http_method(self) -> str:
26+
return self["httpMethod"]
27+
28+
@property
29+
def path(self) -> str:
30+
return self["path"]
31+
32+
@property
33+
def multi_value_query_string_parameters(self) -> Optional[Dict[str, List[str]]]:
34+
return self.get("multiValueQueryStringParameters")
35+
36+
@property
37+
def multi_value_headers(self) -> Optional[Dict[str, List[str]]]:
38+
return self.get("multiValueHeaders")

0 commit comments

Comments
 (0)