Skip to content

Commit

Permalink
docs(data_classes): fix missing dynamodb stream get_type/value
Browse files Browse the repository at this point in the history
  • Loading branch information
heitorlessa committed Jun 8, 2021
1 parent b8bc313 commit 8724294
Showing 1 changed file with 36 additions and 15 deletions.
51 changes: 36 additions & 15 deletions docs/utilities/data_classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,21 +556,42 @@ attributes values (`AttributeValue`), as well as enums for stream view type (`St

=== "app.py"

```python
from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import (
DynamoDBStreamEvent,
DynamoDBRecordEventName
)

def lambda_handler(event, context):
event: DynamoDBStreamEvent = DynamoDBStreamEvent(event)

# Multiple records can be delivered in a single event
for record in event.records:
if record.event_name == DynamoDBRecordEventName.MODIFY:
do_something_with(record.dynamodb.new_image)
do_something_with(record.dynamodb.old_image)
```
```python
from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import (
DynamoDBStreamEvent,
DynamoDBRecordEventName
)

def lambda_handler(event, context):
event: DynamoDBStreamEvent = DynamoDBStreamEvent(event)

# Multiple records can be delivered in a single event
for record in event.records:
if record.event_name == DynamoDBRecordEventName.MODIFY:
do_something_with(record.dynamodb.new_image)
do_something_with(record.dynamodb.old_image)
```

=== "multiple_records_types.py"

```python
from aws_lambda_powertools.utilities.data_classes import event_source, DynamoDBStreamEvent
from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import AttributeValueType, AttributeValue
from aws_lambda_powertools.utilities.typing import LambdaContext


@event_source(data_class=DynamoDBStreamEvent)
def lambda_handler(event: DynamoDBStreamEvent, context: LambdaContext):
for record in event.records:
key: AttributeValue = record.dynamodb.keys["id"]
if key == AttributeValueType.Number:
# {"N": "123.45"} => "123.45"
assert key.get_value == key.n_value
print(key.get_value)
elif key == AttributeValueType.Map:
assert key.get_value == key.map_value
print(key.get_value)
```

### EventBridge

Expand Down

0 comments on commit 8724294

Please sign in to comment.