@@ -30,18 +30,37 @@ For example, if your Lambda function is being triggered by an API Gateway proxy
30
30
31
31
32
32
## Supported event sources
33
+
34
+ Event Source | Data_class
35
+ ------------------------------------------------- | ---------------------------------------------------------------------------------
36
+ [ API Gateway Proxy] ( #api-gateway-proxy ) | APIGatewayProxyEvent
37
+ [ API Gateway Proxy event v2] ( #api-gateway-proxy-v2 ) | APIGatewayProxyEventV2
38
+ [ CloudWatch Logs] ( #cloudWatch-logs ) | CloudWatchLogsEvent
39
+ [ Cognito User Pool] ( #cognito-user-pool-triggers ) |
40
+ [ DynamoDB streams] ( #dynamoDB-streams ) | DynamoDBStreamEvent, DynamoDBRecordEventName
41
+ [ EventBridge] ( #eventbridge ) | EventBridgeEvent
42
+ [ Kinesis Data Stream] ( #kinesis-streams ) | KinesisStreamEvent
43
+ [ S3] ( #S3 ) | S3Event
44
+ [ SES] ( #SES ) | SESEvent
45
+ [ SNS] ( #SNS ) | SNSEvent
46
+ [ SQS] ( #SQS ) | SQSEvent
47
+
48
+
33
49
<Note type = " info" >
34
50
The examples provided below are far from exhaustive - the data classes themselves are designed to provide a form of
35
51
documentation inherently (via autocompletion, types and docstrings).
36
52
</Note >
37
53
38
54
39
- ### API Gateway Proxy V1 (REST API)
55
+ ## API Gateway Proxy
56
+
57
+ Typically used for API Gateway REST API or HTTP API using v1 proxy event.
58
+
40
59
``` python:title=lambda_app.py
41
60
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
42
61
43
62
def lambda_handler (event , context ):
44
- event = APIGatewayProxyEvent(event)
63
+ event: APIGatewayProxyEvent = APIGatewayProxyEvent(event)
45
64
request_context = event.request_context
46
65
identity = request_context.identity
47
66
@@ -50,7 +69,8 @@ def lambda_handler(event, context):
50
69
do_something_with(event.body, user)
51
70
```
52
71
53
- ### API Gateway Proxy V2 (HTTP API)
72
+ ## API Gateway Proxy v2
73
+
54
74
``` python:title=lambda_app.py
55
75
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEventV2
56
76
@@ -63,8 +83,9 @@ def lambda_handler(event, context):
63
83
do_something_with(event.body, query_string_parameters)
64
84
```
65
85
66
- ### CloudWatch logs
67
- CloudWatch logs events by default are compressed and base64 encoded. You can use the helper function provided to decode,
86
+ ## CloudWatch Logs
87
+
88
+ CloudWatch Logs events by default are compressed and base64 encoded. You can use the helper function provided to decode,
68
89
decompress and parse json data from the event.
69
90
70
91
``` python:title=lambda_app.py
@@ -79,7 +100,8 @@ def lambda_handler(event, context):
79
100
do_something_with(event.timestamp, event.message)
80
101
```
81
102
82
- ### Cognito user pool triggers
103
+ ## Cognito User Pool
104
+
83
105
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
84
106
can be imported from ` aws_lambda_powertools.data_classes.cognito_user_pool_event ` :
85
107
@@ -103,7 +125,8 @@ def lambda_handler(event, context):
103
125
do_something_with(user_attributes)
104
126
```
105
127
106
- ### DynamoDB streams
128
+ ## DynamoDB Streams
129
+
107
130
The DynamoDB data class utility provides the base class for ` DynamoDBStreamEvent ` , a typed class for
108
131
attributes values (` AttributeValue ` ), as well as enums for stream view type (` StreamViewType ` ) and event type
109
132
(` DynamoDBRecordEventName ` ).
@@ -121,7 +144,8 @@ def lambda_handler(event, context):
121
144
do_something_with(record.dynamodb.old_image)
122
145
```
123
146
124
- ### EventBridge
147
+ ## EventBridge
148
+
125
149
``` python:title=lambda_app.py
126
150
from aws_lambda_powertools.utilities.data_classes import EventBridgeEvent
127
151
@@ -131,9 +155,11 @@ def lambda_handler(event, context):
131
155
132
156
```
133
157
134
- ### Kinesis streams
158
+ ## Kinesis streams
159
+
135
160
Kinesis events by default contain base64 encoded data. You can use the helper function to access the data either as json
136
161
or plain text, depending on the original payload.
162
+
137
163
``` python:title=lambda_app.py
138
164
from aws_lambda_powertools.utilities.data_classes import KinesisStreamEvent
139
165
@@ -150,7 +176,8 @@ def lambda_handler(event, context):
150
176
151
177
```
152
178
153
- ### S3 events
179
+ ## S3
180
+
154
181
``` python:title=lambda_app.py
155
182
from aws_lambda_powertools.utilities.data_classes import S3Event
156
183
@@ -166,7 +193,8 @@ def lambda_handler(event, context):
166
193
167
194
```
168
195
169
- ### SES events
196
+ ## SES
197
+
170
198
``` python:title=lambda_app.py
171
199
from aws_lambda_powertools.utilities.data_classes import SESEvent
172
200
@@ -182,7 +210,8 @@ def lambda_handler(event, context):
182
210
183
211
```
184
212
185
- ### SNS
213
+ ## SNS
214
+
186
215
``` python:title=lambda_app.py
187
216
from aws_lambda_powertools.utilities.data_classes import SNSEvent
188
217
@@ -197,7 +226,8 @@ def lambda_handler(event, context):
197
226
do_something_with(subject, message)
198
227
```
199
228
200
- ### SQS
229
+ ## SQS
230
+
201
231
``` python:title=lambda_app.py
202
232
from aws_lambda_powertools.utilities.data_classes import SQSEvent
203
233
0 commit comments