Skip to content

Commit d900b12

Browse files
committed
docs: cleanup persistence layers attrs, snippet titles etc
Signed-off-by: heitorlessa <[email protected]>
1 parent 55a9fc6 commit d900b12

File tree

1 file changed

+80
-10
lines changed

1 file changed

+80
-10
lines changed

docs/utilities/idempotency.md

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,13 @@ If an exception is handled or raised **outside** your decorated function, then i
369369

370370
This persistence layer is built-in, allowing you to use an existing DynamoDB table or create a new one dedicated to idempotency state (recommended).
371371

372-
```python title="customize_persistence_layer.py" hl_lines="10-18"
372+
```python title="customize_persistence_layer.py" hl_lines="7-15"
373373
--8<-- "examples/idempotency/src/customize_persistence_layer.py"
374374
```
375375

376-
```python hl_lines="7-15"
377-
--8<-- "examples/idempotency/src/customize_persistence_layer.py"
378-
```
379-
380-
##### DynamoDB defaults
376+
##### DynamoDB attributes
381377

382-
When using DynamoDB as the persistence layer, you can customize the attribute names by passing the following parameters during the initialization of the persistence layer:
378+
You can customize the attribute names during initialization:
383379

384380
| Parameter | Required | Default | Description |
385381
| --------------------------- | ------------------ | ------------------------------------ | -------------------------------------------------------------------------------------------------------- |
@@ -397,27 +393,101 @@ When using DynamoDB as the persistence layer, you can customize the attribute na
397393

398394
!!! info "We recommend Redis version 7 or higher for optimal performance."
399395

400-
For a quick start, initialize `RedisCachePersistenceLayer` and pass your cluster host endpoint along with the port to connect to.
396+
For simple setups, initialize `RedisCachePersistenceLayer` with your cluster endpoint and port to connect.
401397

402398
For security, we enforce SSL connections by default; to disable it, set `ssl=False`.
403399

404400
=== "Redis quick start"
405-
```python title="getting_started_with_idempotency_redis_config.py" hl_lines="8-10 14 27"
401+
```python title="getting_started_with_idempotency_redis_config.py" hl_lines="7-9 12 26"
406402
--8<-- "examples/idempotency/src/getting_started_with_idempotency_redis_config.py"
407403
```
408404

409405
=== "Using an existing Redis client"
410-
```python title="getting_started_with_idempotency_redis_client.py" hl_lines="5 10-11 16 24 38"
406+
```python title="getting_started_with_idempotency_redis_client.py" hl_lines="4 9-11 14 22 36"
411407
--8<-- "examples/idempotency/src/getting_started_with_idempotency_redis_client.py"
412408
```
413409

410+
=== "Sample event"
411+
412+
```json title="getting_started_with_idempotency_payload.json"
413+
--8<-- "examples/idempotency/src/getting_started_with_idempotency_payload.json"
414+
```
415+
416+
##### Redis SSL connections
417+
418+
We recommend using AWS Secrets Manager to store and rotate certificates safely, and the [Parameters feature](./parameters.md){target="_blank"} to fetch and cache optimally.
419+
420+
For advanced configurations, we recommend using an existing Redis client for optimal compatibility like SSL certificates and timeout.
421+
422+
=== "Advanced configuration using AWS Secrets"
423+
```python title="using_redis_client_with_aws_secrets.py" hl_lines="9-11 13 15 25"
424+
--8<-- "examples/idempotency/src/using_redis_client_with_aws_secrets.py"
425+
```
426+
427+
1. JSON stored:
428+
```json
429+
{
430+
"REDIS_ENDPOINT": "127.0.0.1",
431+
"REDIS_PORT": "6379",
432+
"REDIS_PASSWORD": "redis-secret"
433+
}
434+
```
435+
436+
=== "Advanced configuration with local certificates"
437+
```python title="using_redis_client_with_local_certs.py" hl_lines="14 25-27"
438+
--8<-- "examples/idempotency/src/using_redis_client_with_local_certs.py"
439+
```
440+
441+
1. JSON stored:
442+
```json
443+
{
444+
"REDIS_ENDPOINT": "127.0.0.1",
445+
"REDIS_PORT": "6379",
446+
"REDIS_PASSWORD": "redis-secret"
447+
}
448+
```
449+
2. redis_user.crt file stored in the "certs" directory of your Lambda function
450+
3. redis_user_private.key file stored in the "certs" directory of your Lambda function
451+
4. redis_ca.pem file stored in the "certs" directory of your Lambda function
452+
453+
##### Redis attributes
454+
455+
You can customize the attribute names during initialization:
456+
414457
| Parameter | Required | Default | Description |
415458
| --------------------------- | -------- | ------------------------ | --------------------------------------------------------------------------------------------- |
416459
| **in_progress_expiry_attr** | | `in_progress_expiration` | Unix timestamp of when record expires while in progress (in case of the invocation times out) |
417460
| **status_attr** | | `status` | Stores status of the Lambda execution during and after invocation |
418461
| **data_attr** | | `data` | Stores results of successfully executed Lambda handlers |
419462
| **validation_key_attr** | | `validation` | Hashed representation of the parts of the event used for validation |
420463

464+
```python title="customize_persistence_layer_redis.py" hl_lines="9-16"
465+
--8<-- "examples/idempotency/src/customize_persistence_layer_redis.py"
466+
```
467+
468+
### Common use cases
469+
470+
#### Batch integration
471+
472+
You can can easily integrate with [Batch](batch.md){target="_blank"} with the [idempotent_function decorator](#idempotent_function-decorator) to handle idempotency per message/record in a given batch.
473+
474+
???+ "Choosing an unique batch record attribute"
475+
In this example, we choose `messageId` as our idempotency key since we know it'll be unique.
476+
477+
Depending on your use case, it might be more accurate [to choose another field](#choosing-a-payload-subset-for-idempotency) your producer intentionally set to define uniqueness.
478+
479+
=== "Integration with Batch Processor"
480+
481+
```python title="integrate_idempotency_with_batch_processor.py" hl_lines="3 16 19 25 27"
482+
--8<-- "examples/idempotency/src/integrate_idempotency_with_batch_processor.py"
483+
```
484+
485+
=== "Sample event"
486+
487+
```json title="integrate_idempotency_with_batch_processor_payload.json" hl_lines="4"
488+
--8<-- "examples/idempotency/src/integrate_idempotency_with_batch_processor_payload.json"
489+
```
490+
421491
### Idempotency request flow
422492

423493
The following sequence diagrams explain how the Idempotency feature behaves under different scenarios.

0 commit comments

Comments
 (0)