Skip to content

Commit 8837b1d

Browse files
committed
docs: moved composite key under DDB section
1 parent aa25c42 commit 8837b1d

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

docs/utilities/idempotency.md

+28-28
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,34 @@ This persistence layer is built-in, allowing you to use an existing DynamoDB tab
373373
--8<-- "examples/idempotency/src/customize_persistence_layer.py"
374374
```
375375

376+
##### Using a composite primary key
377+
378+
Use `sort_key_attr` parameter when your table is configured with a composite primary key _(hash+range key)_.
379+
380+
When enabled, we will save the idempotency key in the sort key instead. By default, the primary key will now be set to `idempotency#{LAMBDA_FUNCTION_NAME}`.
381+
382+
You can optionally set a static value for the partition key using the `static_pk_value` parameter.
383+
384+
=== "Reusing a DynamoDB table that uses a composite primary key"
385+
386+
```python hl_lines="10"
387+
--8<-- "examples/idempotency/src/working_with_composite_key.py"
388+
```
389+
390+
=== "Sample Event"
391+
392+
```json
393+
--8<-- "examples/idempotency/src/working_with_composite_key_payload.json"
394+
```
395+
396+
??? note "Click to expand and learn how table items would look like"
397+
398+
| id | sort_key | expiration | status | data |
399+
| ---------------------------- | -------------------------------- | ---------- | ----------- | ----------------------------------------- |
400+
| idempotency#MyLambdaFunction | 1e956ef7da78d0cb890be999aecc0c9e | 1636549553 | COMPLETED | {"user_id": 12391, "message": "success"} |
401+
| idempotency#MyLambdaFunction | 2b2cdb5f86361e97b4383087c1ffdf27 | 1636549571 | COMPLETED | {"user_id": 527212, "message": "success"} |
402+
| idempotency#MyLambdaFunction | f091d2527ad1c78f05d54cc3f363be80 | 1636549585 | IN_PROGRESS | |
403+
376404
##### DynamoDB attributes
377405

378406
You can customize the attribute names during initialization:
@@ -871,34 +899,6 @@ The **`boto_config`** and **`boto3_session`** parameters enable you to pass in a
871899
--8<-- "examples/idempotency/src/working_with_custom_config_payload.json"
872900
```
873901

874-
### Using a DynamoDB table with a composite primary key
875-
876-
When using a composite primary key table (hash+range key), use `sort_key_attr` parameter when initializing your persistence layer.
877-
878-
With this setting, we will save the idempotency key in the sort key instead of the primary key. By default, the primary key will now be set to `idempotency#{LAMBDA_FUNCTION_NAME}`.
879-
880-
You can optionally set a static value for the partition key using the `static_pk_value` parameter.
881-
882-
=== "Reusing a DynamoDB table that uses a composite primary key"
883-
884-
```python hl_lines="10"
885-
--8<-- "examples/idempotency/src/working_with_composite_key.py"
886-
```
887-
888-
=== "Sample Event"
889-
890-
```json
891-
--8<-- "examples/idempotency/src/working_with_composite_key_payload.json"
892-
```
893-
894-
The example function above would cause data to be stored in DynamoDB like this:
895-
896-
| id | sort_key | expiration | status | data |
897-
| ---------------------------- | -------------------------------- | ---------- | ----------- | ----------------------------------------- |
898-
| idempotency#MyLambdaFunction | 1e956ef7da78d0cb890be999aecc0c9e | 1636549553 | COMPLETED | {"user_id": 12391, "message": "success"} |
899-
| idempotency#MyLambdaFunction | 2b2cdb5f86361e97b4383087c1ffdf27 | 1636549571 | COMPLETED | {"user_id": 527212, "message": "success"} |
900-
| idempotency#MyLambdaFunction | f091d2527ad1c78f05d54cc3f363be80 | 1636549585 | IN_PROGRESS | |
901-
902902
### Bring your own persistent store
903903

904904
This utility provides an abstract base class (ABC), so that you can implement your choice of persistent storage layer.

0 commit comments

Comments
 (0)