Skip to content

Commit c047b7a

Browse files
author
Tom McCarthy
committed
Merge remote-tracking branch 'origin/docs/data_classes' into docs/data_classes
2 parents 902c8db + a536a65 commit c047b7a

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

docs/content/utilities/data_classes.mdx

+43-13
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,37 @@ For example, if your Lambda function is being triggered by an API Gateway proxy
3030

3131

3232
## 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+
3349
<Note type="info">
3450
The examples provided below are far from exhaustive - the data classes themselves are designed to provide a form of
3551
documentation inherently (via autocompletion, types and docstrings).
3652
</Note>
3753

3854

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+
4059
```python:title=lambda_app.py
4160
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
4261

4362
def lambda_handler(event, context):
44-
event = APIGatewayProxyEvent(event)
63+
event: APIGatewayProxyEvent = APIGatewayProxyEvent(event)
4564
request_context = event.request_context
4665
identity = request_context.identity
4766

@@ -50,7 +69,8 @@ def lambda_handler(event, context):
5069
do_something_with(event.body, user)
5170
```
5271

53-
### API Gateway Proxy V2 (HTTP API)
72+
## API Gateway Proxy v2
73+
5474
```python:title=lambda_app.py
5575
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEventV2
5676

@@ -63,8 +83,9 @@ def lambda_handler(event, context):
6383
do_something_with(event.body, query_string_parameters)
6484
```
6585

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,
6889
decompress and parse json data from the event.
6990

7091
```python:title=lambda_app.py
@@ -79,7 +100,8 @@ def lambda_handler(event, context):
79100
do_something_with(event.timestamp, event.message)
80101
```
81102

82-
### Cognito user pool triggers
103+
## Cognito User Pool
104+
83105
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
84106
can be imported from `aws_lambda_powertools.data_classes.cognito_user_pool_event`:
85107

@@ -103,7 +125,8 @@ def lambda_handler(event, context):
103125
do_something_with(user_attributes)
104126
```
105127

106-
### DynamoDB streams
128+
## DynamoDB Streams
129+
107130
The DynamoDB data class utility provides the base class for `DynamoDBStreamEvent`, a typed class for
108131
attributes values (`AttributeValue`), as well as enums for stream view type (`StreamViewType`) and event type
109132
(`DynamoDBRecordEventName`).
@@ -121,7 +144,8 @@ def lambda_handler(event, context):
121144
do_something_with(record.dynamodb.old_image)
122145
```
123146

124-
### EventBridge
147+
## EventBridge
148+
125149
```python:title=lambda_app.py
126150
from aws_lambda_powertools.utilities.data_classes import EventBridgeEvent
127151

@@ -131,9 +155,11 @@ def lambda_handler(event, context):
131155

132156
```
133157

134-
### Kinesis streams
158+
## Kinesis streams
159+
135160
Kinesis events by default contain base64 encoded data. You can use the helper function to access the data either as json
136161
or plain text, depending on the original payload.
162+
137163
```python:title=lambda_app.py
138164
from aws_lambda_powertools.utilities.data_classes import KinesisStreamEvent
139165

@@ -150,7 +176,8 @@ def lambda_handler(event, context):
150176

151177
```
152178

153-
### S3 events
179+
## S3
180+
154181
```python:title=lambda_app.py
155182
from aws_lambda_powertools.utilities.data_classes import S3Event
156183

@@ -166,7 +193,8 @@ def lambda_handler(event, context):
166193

167194
```
168195

169-
### SES events
196+
## SES
197+
170198
```python:title=lambda_app.py
171199
from aws_lambda_powertools.utilities.data_classes import SESEvent
172200

@@ -182,7 +210,8 @@ def lambda_handler(event, context):
182210

183211
```
184212

185-
### SNS
213+
## SNS
214+
186215
```python:title=lambda_app.py
187216
from aws_lambda_powertools.utilities.data_classes import SNSEvent
188217

@@ -197,7 +226,8 @@ def lambda_handler(event, context):
197226
do_something_with(subject, message)
198227
```
199228

200-
### SQS
229+
## SQS
230+
201231
```python:title=lambda_app.py
202232
from aws_lambda_powertools.utilities.data_classes import SQSEvent
203233

0 commit comments

Comments
 (0)