@@ -5,7 +5,7 @@ description: Utility
5
5
6
6
The event source data classes utility provides classes describing the schema of common Lambda events triggers.
7
7
8
- ** Key Features**
8
+ ## Key Features
9
9
10
10
* Type hinting and code completion for common event types
11
11
* Helper functions for decoding/deserializing nested fields
@@ -17,13 +17,30 @@ When authoring Lambda functions, you often need to understand the schema of the
17
17
handler. There are several common event types which follow a specific schema, depending on the service triggering the
18
18
Lambda function.
19
19
20
+ ## Getting started
20
21
21
- ## Utilizing the data classes
22
+ ### Utilizing the data classes
22
23
23
24
The classes are initialized by passing in the Lambda event object into the constructor of the appropriate data class.
25
+
24
26
For example, if your Lambda function is being triggered by an API Gateway proxy integration, you can use the
25
27
` APIGatewayProxyEvent ` class.
26
28
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
+
27
44
![ Utilities Data Classes] ( ../media/utilities_data_classes.png )
28
45
29
46
@@ -49,7 +66,7 @@ Event Source | Data_class
49
66
documentation inherently (via autocompletion, types and docstrings).
50
67
51
68
52
- ## API Gateway Proxy
69
+ ### API Gateway Proxy
53
70
54
71
Typically used for API Gateway REST API or HTTP API using v1 proxy event.
55
72
@@ -68,7 +85,7 @@ Typically used for API Gateway REST API or HTTP API using v1 proxy event.
68
85
do_something_with(event.body, user)
69
86
```
70
87
71
- ## API Gateway Proxy v2
88
+ ### API Gateway Proxy v2
72
89
73
90
=== "lambda_app.py"
74
91
@@ -84,7 +101,7 @@ Typically used for API Gateway REST API or HTTP API using v1 proxy event.
84
101
do_something_with(event.body, query_string_parameters)
85
102
```
86
103
87
- ## CloudWatch Logs
104
+ ### CloudWatch Logs
88
105
89
106
CloudWatch Logs events by default are compressed and base64 encoded. You can use the helper function provided to decode,
90
107
decompress and parse json data from the event.
@@ -103,7 +120,7 @@ decompress and parse json data from the event.
103
120
do_something_with(event.timestamp, event.message)
104
121
```
105
122
106
- ## Cognito User Pool
123
+ ### Cognito User Pool
107
124
108
125
Cognito 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
109
126
can 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
133
150
do_something_with(user_attributes)
134
151
```
135
152
136
- ## DynamoDB Streams
153
+ ### DynamoDB Streams
137
154
138
155
The DynamoDB data class utility provides the base class for ` DynamoDBStreamEvent ` , a typed class for
139
156
attributes 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
154
171
do_something_with(record.dynamodb.old_image)
155
172
```
156
173
157
- ## EventBridge
174
+ ### EventBridge
158
175
159
176
=== "lambda_app.py"
160
177
@@ -167,7 +184,7 @@ attributes values (`AttributeValue`), as well as enums for stream view type (`St
167
184
168
185
```
169
186
170
- ## Kinesis streams
187
+ ### Kinesis streams
171
188
172
189
Kinesis events by default contain base64 encoded data. You can use the helper function to access the data either as json
173
190
or plain text, depending on the original payload.
@@ -189,7 +206,7 @@ or plain text, depending on the original payload.
189
206
do_something_with(data)
190
207
```
191
208
192
- ## S3
209
+ ### S3
193
210
194
211
=== "lambda_app.py"
195
212
@@ -207,7 +224,7 @@ or plain text, depending on the original payload.
207
224
do_something_with(f'{bucket_name}/{object_key}')
208
225
```
209
226
210
- ## SES
227
+ ### SES
211
228
212
229
=== "lambda_app.py"
213
230
@@ -225,7 +242,7 @@ or plain text, depending on the original payload.
225
242
do_something_with(common_headers.to, common_headers.subject)
226
243
```
227
244
228
- ## SNS
245
+ ### SNS
229
246
230
247
=== "lambda_app.py"
231
248
@@ -243,7 +260,7 @@ or plain text, depending on the original payload.
243
260
do_something_with(subject, message)
244
261
```
245
262
246
- ## SQS
263
+ ### SQS
247
264
248
265
=== "lambda_app.py"
249
266
@@ -257,3 +274,25 @@ or plain text, depending on the original payload.
257
274
for record in event.records:
258
275
do_something_with(record.body)
259
276
```
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