@@ -5,7 +5,7 @@ description: Utility
55
66The event source data classes utility provides classes describing the schema of common Lambda events triggers.
77
8- ** Key Features**
8+ ## Key Features
99
1010* Type hinting and code completion for common event types
1111* Helper functions for decoding/deserializing nested fields
@@ -17,13 +17,30 @@ When authoring Lambda functions, you often need to understand the schema of the
1717handler. There are several common event types which follow a specific schema, depending on the service triggering the
1818Lambda function.
1919
20+ ## Getting started
2021
21- ## Utilizing the data classes
22+ ### Utilizing the data classes
2223
2324The classes are initialized by passing in the Lambda event object into the constructor of the appropriate data class.
25+
2426For example, if your Lambda function is being triggered by an API Gateway proxy integration, you can use the
2527` APIGatewayProxyEvent ` class.
2628
29+ === "app.py"
30+
31+ ```python hl_lines="1 4"
32+ from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
33+
34+ def lambda_handler(event, context):
35+ event: APIGatewayProxyEvent = APIGatewayProxyEvent(event)
36+
37+ if 'helloworld' in event.path && event.http_method == 'GET':
38+ do_something_with(event.body, user)
39+ ```
40+
41+ ** Autocomplete with self-documented properties and methods**
42+
43+
2744![ Utilities Data Classes] ( ../media/utilities_data_classes.png )
2845
2946
@@ -49,7 +66,7 @@ Event Source | Data_class
4966 documentation inherently (via autocompletion, types and docstrings).
5067
5168
52- ## API Gateway Proxy
69+ ### API Gateway Proxy
5370
5471Typically used for API Gateway REST API or HTTP API using v1 proxy event.
5572
@@ -68,7 +85,7 @@ Typically used for API Gateway REST API or HTTP API using v1 proxy event.
6885 do_something_with(event.body, user)
6986 ```
7087
71- ## API Gateway Proxy v2
88+ ### API Gateway Proxy v2
7289
7390=== "lambda_app.py"
7491
@@ -84,7 +101,7 @@ Typically used for API Gateway REST API or HTTP API using v1 proxy event.
84101 do_something_with(event.body, query_string_parameters)
85102 ```
86103
87- ## CloudWatch Logs
104+ ### CloudWatch Logs
88105
89106CloudWatch Logs events by default are compressed and base64 encoded. You can use the helper function provided to decode,
90107decompress and parse json data from the event.
@@ -103,7 +120,7 @@ decompress and parse json data from the event.
103120 do_something_with(event.timestamp, event.message)
104121 ```
105122
106- ## Cognito User Pool
123+ ### Cognito User Pool
107124
108125Cognito User Pools have several [ different Lambda trigger sources] ( https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html#cognito-user-identity-pools-working-with-aws-lambda-trigger-sources ) , all of which map to a different data class, which
109126can be imported from ` aws_lambda_powertools.data_classes.cognito_user_pool_event ` :
@@ -133,7 +150,7 @@ Verify Auth Challenge | `data_classes.cognito_user_pool_event.VerifyAuthChalleng
133150 do_something_with(user_attributes)
134151 ```
135152
136- ## DynamoDB Streams
153+ ### DynamoDB Streams
137154
138155The DynamoDB data class utility provides the base class for ` DynamoDBStreamEvent ` , a typed class for
139156attributes values (` AttributeValue ` ), as well as enums for stream view type (` StreamViewType ` ) and event type
@@ -154,7 +171,7 @@ attributes values (`AttributeValue`), as well as enums for stream view type (`St
154171 do_something_with(record.dynamodb.old_image)
155172 ```
156173
157- ## EventBridge
174+ ### EventBridge
158175
159176=== "lambda_app.py"
160177
@@ -167,7 +184,7 @@ attributes values (`AttributeValue`), as well as enums for stream view type (`St
167184
168185 ```
169186
170- ## Kinesis streams
187+ ### Kinesis streams
171188
172189Kinesis events by default contain base64 encoded data. You can use the helper function to access the data either as json
173190or plain text, depending on the original payload.
@@ -189,7 +206,7 @@ or plain text, depending on the original payload.
189206 do_something_with(data)
190207 ```
191208
192- ## S3
209+ ### S3
193210
194211=== "lambda_app.py"
195212
@@ -207,7 +224,7 @@ or plain text, depending on the original payload.
207224 do_something_with(f'{bucket_name}/{object_key}')
208225 ```
209226
210- ## SES
227+ ### SES
211228
212229=== "lambda_app.py"
213230
@@ -225,7 +242,7 @@ or plain text, depending on the original payload.
225242 do_something_with(common_headers.to, common_headers.subject)
226243 ```
227244
228- ## SNS
245+ ### SNS
229246
230247=== "lambda_app.py"
231248
@@ -243,7 +260,7 @@ or plain text, depending on the original payload.
243260 do_something_with(subject, message)
244261 ```
245262
246- ## SQS
263+ ### SQS
247264
248265=== "lambda_app.py"
249266
@@ -257,3 +274,25 @@ or plain text, depending on the original payload.
257274 for record in event.records:
258275 do_something_with(record.body)
259276 ```
277+
278+ ### Connect
279+
280+ ** Connect Contact Flow**
281+
282+ === "lambda_app.py"
283+
284+ ```python
285+ from aws_lambda_powertools.utilities.data_classes.connect_contact_flow_event import (
286+ ConnectContactFlowChannel,
287+ ConnectContactFlowEndpointType,
288+ ConnectContactFlowEvent,
289+ ConnectContactFlowInitiationMethod,
290+ )
291+
292+ def lambda_handler(event, context):
293+ event: ConnectContactFlowEvent = ConnectContactFlowEvent(event)
294+ assert event.contact_data.attributes == {"Language": "en-US"}
295+ assert event.contact_data.channel == ConnectContactFlowChannel.VOICE
296+ assert event.contact_data.customer_endpoint.endpoint_type == ConnectContactFlowEndpointType.TELEPHONE_NUMBER
297+ assert event.contact_data.initiation_method == ConnectContactFlowInitiationMethod.API
298+ ```
0 commit comments