Skip to content

Commit

Permalink
docs(idempotency): Correct examples and line highlights (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brewer authored Mar 6, 2021
1 parent 696f93e commit 8b6a68b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ A suite of Python utilities for AWS Lambda functions to ease adopting best pract
* **[Metrics](https://awslabs.github.io/aws-lambda-powertools-python/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
* **[Bring your own middleware](https://awslabs.github.io/aws-lambda-powertools-python/utilities/middleware_factory/)** - Decorator factory to create your own middleware to run logic before, and after each Lambda invocation
* **[Parameters utility](https://awslabs.github.io/aws-lambda-powertools-python/utilities/parameters/)** - Retrieve and cache parameter values from Parameter Store, Secrets Manager, or DynamoDB
* **[Batch processing](https://awslabs.github.io/aws-lambda-powertools-python/utilities/batch)** - Handle partial failures for AWS SQS batch processing
* **[Typing](https://awslabs.github.io/aws-lambda-powertools-python/utilities/typing)** - Static typing classes to speedup development in your IDE
* **[Validation](https://awslabs.github.io/aws-lambda-powertools-python/utilities/validation)** - JSON Schema validator for inbound events and responses
* **[Event source data classes](https://awslabs.github.io/aws-lambda-powertools-python/utilities/data_classes)** - Data classes describing the schema of common Lambda event triggers
* **[Parser](https://awslabs.github.io/aws-lambda-powertools-python/utilities/parser)** - Data parsing and deep validation using Pydantic
* **[Batch processing](https://awslabs.github.io/aws-lambda-powertools-python/utilities/batch/)** - Handle partial failures for AWS SQS batch processing
* **[Typing](https://awslabs.github.io/aws-lambda-powertools-python/utilities/typing/)** - Static typing classes to speedup development in your IDE
* **[Validation](https://awslabs.github.io/aws-lambda-powertools-python/utilities/validation/)** - JSON Schema validator for inbound events and responses
* **[Event source data classes](https://awslabs.github.io/aws-lambda-powertools-python/utilities/data_classes/)** - Data classes describing the schema of common Lambda event triggers
* **[Parser](https://awslabs.github.io/aws-lambda-powertools-python/utilities/parser/)** - Data parsing and deep validation using Pydantic
* **[Idempotency](https://awslabs.github.io/aws-lambda-powertools-python/utilities/idempotency/)** - Convert your Lambda functions into idempotent operations which are safe to retry

### Installation

Expand Down
18 changes: 9 additions & 9 deletions docs/utilities/idempotency.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ You can quickly start by initializing the `DynamoDBPersistenceLayer` class and u

=== "app.py"

```python hl_lines="1 5 7 14"
```python hl_lines="1-3 5 7 14"
from aws_lambda_powertools.utilities.idempotency import (
DynamoDBPersistenceLayer, idempotent
)
Expand Down Expand Up @@ -186,7 +186,7 @@ Imagine the function executes successfully, but the client never receives the re
"time":"10/Feb/2021:13:40:43 +0000",
"timeEpoch":1612964443723
},
"body":"{\"username\":\"xyz\",\"product_id\":\"123456789\"}",
"body":"{\"user\":\"xyz\",\"product_id\":\"123456789\"}",
"isBase64Encoded":false
}
```
Expand Down Expand Up @@ -223,7 +223,7 @@ This persistence layer is built-in, and you can either use an existing DynamoDB

=== "app.py"

```python hl_lines="3-7"
```python hl_lines="5-9"
from aws_lambda_powertools.utilities.idempotency import DynamoDBPersistenceLayer

persistence_layer = DynamoDBPersistenceLayer(
Expand All @@ -232,7 +232,7 @@ This persistence layer is built-in, and you can either use an existing DynamoDB
expiry_attr="expires_at",
status_attr="current_status",
data_attr="result_data",
validation_key_attr="validation_key"
validation_key_attr="validation_key",
)
```

Expand All @@ -246,6 +246,7 @@ Parameter | Required | Default | Description
**status_attr** | | `status` | Stores status of the lambda execution during and after invocation
**data_attr** | | `data` | Stores results of successfully executed Lambda handlers
**validation_key_attr** | | `validation` | Hashed representation of the parts of the event used for validation

## Advanced

### Customizing the default behavior
Expand All @@ -259,7 +260,7 @@ Parameter | Default | Description
**raise_on_no_idempotency_key** | `False` | Raise exception if no idempotency key was found in the request
**expires_after_seconds** | 3600 | The number of seconds to wait before a record is expired
**use_local_cache** | `False` | Whether to locally cache idempotency results
**local_cache_max_items** | 1024 | Max number of items to store in local cache
**local_cache_max_items** | 256 | Max number of items to store in local cache
**hash_function** | `md5` | Function to use for calculating hashes, as provided by [hashlib](https://docs.python.org/3/library/hashlib.html) in the standard library.

### Handling concurrent executions with the same payload
Expand All @@ -281,16 +282,15 @@ You can enable in-memory caching with the **`use_local_cache`** parameter:

=== "app.py"

```python hl_lines="6 8 11"
```python hl_lines="8 11"
from aws_lambda_powertools.utilities.idempotency import (
IdempotencyConfig, DynamoDBPersistenceLayer, idempotent
)

persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable")
config = IdempotencyConfig(
event_key_jmespath="body",
expires_after_seconds=5*60, # 5 minutes
use_local_cache=True
use_local_cache=True,
)

@idempotent(config=config, persistence_store=persistence_layer)
Expand All @@ -310,7 +310,7 @@ You can change this window with the **`expires_after_seconds`** parameter:

=== "app.py"

```python hl_lines="6 8 11"
```python hl_lines="8 11"
from aws_lambda_powertools.utilities.idempotency import (
IdempotencyConfig, DynamoDBPersistenceLayer, idempotent
)
Expand Down
Empty file removed examples/__init__.py
Empty file.

0 comments on commit 8b6a68b

Please sign in to comment.