Skip to content

Commit 4f3988a

Browse files
committed
docs: moved composite key under DDB section
1 parent 696caa3 commit 4f3988a

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

docs/utilities/idempotency.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,34 @@ This persistence layer is built-in, allowing you to use an existing DynamoDB tab
359359
--8<-- "examples/idempotency/src/customize_persistence_layer.py"
360360
```
361361

362+
##### Using a composite primary key
363+
364+
Use `sort_key_attr` parameter when your table is configured with a composite primary key _(hash+range key)_.
365+
366+
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}`.
367+
368+
You can optionally set a static value for the partition key using the `static_pk_value` parameter.
369+
370+
=== "Reusing a DynamoDB table that uses a composite primary key"
371+
372+
```python hl_lines="10"
373+
--8<-- "examples/idempotency/src/working_with_composite_key.py"
374+
```
375+
376+
=== "Sample Event"
377+
378+
```json
379+
--8<-- "examples/idempotency/src/working_with_composite_key_payload.json"
380+
```
381+
382+
??? note "Click to expand and learn how table items would look like"
383+
384+
| id | sort_key | expiration | status | data |
385+
| ---------------------------- | -------------------------------- | ---------- | ----------- | ----------------------------------------- |
386+
| idempotency#MyLambdaFunction | 1e956ef7da78d0cb890be999aecc0c9e | 1636549553 | COMPLETED | {"user_id": 12391, "message": "success"} |
387+
| idempotency#MyLambdaFunction | 2b2cdb5f86361e97b4383087c1ffdf27 | 1636549571 | COMPLETED | {"user_id": 527212, "message": "success"} |
388+
| idempotency#MyLambdaFunction | f091d2527ad1c78f05d54cc3f363be80 | 1636549585 | IN_PROGRESS | |
389+
362390
##### DynamoDB attributes
363391

364392
You can customize the attribute names during initialization:
@@ -892,34 +920,6 @@ The **`boto_config`** and **`boto3_session`** parameters enable you to pass in a
892920
--8<-- "examples/idempotency/src/working_with_custom_config_payload.json"
893921
```
894922

895-
### Using a DynamoDB table with a composite primary key
896-
897-
When using a composite primary key table (hash+range key), use `sort_key_attr` parameter when initializing your persistence layer.
898-
899-
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}`.
900-
901-
You can optionally set a static value for the partition key using the `static_pk_value` parameter.
902-
903-
=== "Reusing a DynamoDB table that uses a composite primary key"
904-
905-
```python hl_lines="10"
906-
--8<-- "examples/idempotency/src/working_with_composite_key.py"
907-
```
908-
909-
=== "Sample Event"
910-
911-
```json
912-
--8<-- "examples/idempotency/src/working_with_composite_key_payload.json"
913-
```
914-
915-
The example function above would cause data to be stored in DynamoDB like this:
916-
917-
| id | sort_key | expiration | status | data |
918-
| ---------------------------- | -------------------------------- | ---------- | ----------- | ----------------------------------------- |
919-
| idempotency#MyLambdaFunction | 1e956ef7da78d0cb890be999aecc0c9e | 1636549553 | COMPLETED | {"user_id": 12391, "message": "success"} |
920-
| idempotency#MyLambdaFunction | 2b2cdb5f86361e97b4383087c1ffdf27 | 1636549571 | COMPLETED | {"user_id": 527212, "message": "success"} |
921-
| idempotency#MyLambdaFunction | f091d2527ad1c78f05d54cc3f363be80 | 1636549585 | IN_PROGRESS | |
922-
923923
### Bring your own persistent store
924924

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

0 commit comments

Comments
 (0)