You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -73,12 +73,18 @@ We currently support Amazon DynamoDB and Redis as a storage layer. The following
73
73
If you're not [changing the default configuration for the DynamoDB persistence layer](#dynamodbpersistencelayer), this is the expected default configuration:
| TTL attribute name |`expiration`| This can only be configured after your table is created if you're using AWS Console |
79
79
80
-
???+ tip "Tip: You can share a single state table for all functions"
81
-
You can reuse the same DynamoDB table to store idempotency state. We add `module_name` and [qualified name for classes and functions](https://peps.python.org/pep-3155/){target="_blank" rel="nofollow"} in addition to the idempotency key as a hash key.
| TTL attribute name |`expiration`| This can only be configured after your table is created if you're using AWS Console |
84
+
85
+
Note that `fn_qualified_name` means the [qualified name for classes and functions](https://peps.python.org/pep-3155/){target="_blank" rel="nofollow"} defined in PEP-3155.
86
+
87
+
##### DynamoDB IaC examples
82
88
83
89
=== "AWS Serverless Application Model (SAM) example"
84
90
@@ -109,7 +115,24 @@ If you're not [changing the default configuration for the DynamoDB persistence l
109
115
110
116
On subsequent invocations with the same payload, you can expect just 1 `PutItem` request to DynamoDB.
111
117
112
-
**Note:** While we try to minimize requests to DynamoDB to 1 per invocation, if your boto3 version is lower than `1.26.194`, you may experience 2 requests in every invocation. Ensure to check your boto3 version and review the [DynamoDB pricing documentation](https://aws.amazon.com/dynamodb/pricing/){target="_blank"} to estimate the cost.
118
+
We recommend you start with a Redis compatible management services such as [Amazon ElastiCache for Redis](https://aws.amazon.com/elasticache/redis/){target="_blank"} or [Amazon MemoryDB for Redis](https://aws.amazon.com/memorydb/){target="_blank"}.
119
+
120
+
In both services and self-hosting Redis, you'll need to configure [VPC access](https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html){target="_blank"} to your AWS Lambda.
121
+
122
+
!!! tip "First time setting it all up? Checkout the official tutorials for [Amazon ElastiCache for Redis](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/LambdaRedis.html) or [Amazon MemoryDB for Redis](https://aws.amazon.com/blogs/database/access-amazon-memorydb-for-redis-from-aws-lambda/)"
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:
357
382
358
383
| Parameter | Required | Default | Description |
@@ -369,23 +394,82 @@ When using DynamoDB as the persistence layer, you can customize the attribute na
369
394
370
395
#### RedisPersistenceLayer
371
396
372
-
This persistence layer is built-in, allowing you to use an existing Redis service. For optimal performance and compatibility, it is strongly recommended to use a Redis service version 7 or higher.
397
+
!!! info "We recommend Redis version 7 or higher for optimal performance."
398
+
399
+
For a quick start, initialize `RedisCachePersistenceLayer` and pass your cluster host endpoint along with the port to connect to.
400
+
401
+
For security, we enforce SSL connections by default; to disable it, set `ssl=False`.
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.
422
+
423
+
For advanced configurations, we also recommend using an existing Redis client for optimal compatibility like SSL certificates and timeout.
|**in_progress_expiry_attr**||`in_progress_expiration`| Unix timestamp of when record expires while in progress (in case of the invocation times out) |
463
+
|**status_attr**||`status`| Stores status of the Lambda execution during and after invocation |
464
+
|**data_attr**||`data`| Stores results of successfully executed Lambda handlers |
465
+
|**validation_key_attr**||`validation`| Hashed representation of the parts of the event used for validation |
373
466
374
467
=== "Customizing RedisPersistenceLayer to suit your data structure"
When using Redis as the persistence layer, you can customize the attribute names by providing the following parameters upon initialization of the persistence layer:
|**in_progress_expiry_attr**||`in_progress_expiration`| Unix timestamp of when record expires while in progress (in case of the invocation times out) |
385
-
|**status_attr**||`status`| Stores status of the Lambda execution during and after invocation |
386
-
|**data_attr**||`data`| Stores results of successfully executed Lambda handlers |
387
-
|**validation_key_attr**||`validation`| Hashed representation of the parts of the event used for validation |
388
-
389
473
### Idempotency request flow
390
474
391
475
The following sequence diagrams explain how the Idempotency feature behaves under different scenarios.
@@ -638,110 +722,21 @@ graph TD;
638
722
<i>Race condition with Redis</i>
639
723
</center>
640
724
641
-
## Redis as persistent storage layer provider
642
-
643
-
### Redis resources
644
-
645
-
Before setting up Redis as the persistent storage layer provider, you must have an existing Redis service. We recommend you to use Redis compatible services such as [Amazon ElastiCache for Redis](https://aws.amazon.com/elasticache/redis/){target="_blank"} or [Amazon MemoryDB for Redis](https://aws.amazon.com/memorydb/){target="_blank"} as your persistent storage layer provider.
646
-
647
-
???+ tip "No existing Redis service?"
648
-
If you don't have an existing Redis service, we recommend using [DynamoDB](#dynamodbpersistencelayer) as the persistent storage layer provider.
1. Replace the Security Group ID and Subnet ID to match your VPC settings.
657
-
658
-
### VPC Access
659
-
660
-
Your Lambda Function must have network access to the Redis endpoint before using it as the idempotency persistent storage layer. In most cases, you will need to [configure VPC access](https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html){target="_blank"} for your Lambda Function.
661
-
662
-
???+ tip "Amazon ElastiCache/MemoryDB for Redis as persistent storage layer provider"
663
-
If you plan to use Amazon ElastiCache for Redis as the idempotency persistent storage layer, you may find [this AWS tutorial](https://docs.aws.amazon.com/lambda/latest/dg/services-elasticache-tutorial.html){target="_blank"} helpful.
664
-
For those using Amazon MemoryDB for Redis, refer to [this AWS tutorial](https://aws.amazon.com/blogs/database/access-amazon-memorydb-for-redis-from-aws-lambda/){target="_blank"} specifically for the VPC setup guidance.
665
-
666
-
After completing the VPC setup, you can use the templates provided below to set up Lambda functions with access to VPC internal subnets.
667
-
668
-
=== "AWS Serverless Application Model (SAM) example"
1. Replace the Security Group ID and Subnet ID to match your VPC settings.
675
-
676
-
### Configuring Redis persistence layer
677
-
678
-
You can quickly get started by initializing the `RedisCachePersistenceLayer` class and applying the `idempotent` decorator to your Lambda handler. For a detailed example of using the `RedisCachePersistenceLayer`, refer to the [Persistence layers section](#redispersistencelayer).
679
-
680
-
???+ info
681
-
We enforce security best practices by using SSL connections in the `RedisCachePersistenceLayer`; to disable it, set `ssl=False`
682
-
683
-
=== "Use Persistence Layer with Redis config variables"
For advanced configurations, such as setting up SSL certificates or customizing parameters like a custom timeout, you can utilize the Redis client to tailor these specific settings to your needs.
2. redis_user.crt file stored in the "certs" directory of your Lambda function
727
-
3. redis_user_private.key file stored in the "certs" directory of your Lambda function
728
-
4. redis_ca.pem file stored in the "certs" directory of your Lambda function
729
-
730
725
## Advanced
731
726
732
727
### Customizing the default behavior
733
728
734
729
Idempotent decorator can be further configured with **`IdempotencyConfig`** as seen in the previous example. These are the available options for further configuration
|**event_key_jmespath**|`""`| JMESPath expression to extract the idempotency key from the event record using [built-in functions](./jmespath_functions.md#built-in-jmespath-functions){target="_blank"} |
739
-
|**payload_validation_jmespath**|`""`| JMESPath expression to validate whether certain parameters have changed in the event while the event payload |
740
-
|**raise_on_no_idempotency_key**|`False`| Raise exception if no idempotency key was found in the request |
741
-
|**expires_after_seconds**| 3600 | The number of seconds to wait before a record is expired |
742
-
|**use_local_cache**|`False`| Whether to locally cache idempotency results |
743
-
|**local_cache_max_items**| 256 | Max number of items to store in local cache |
744
-
|**hash_function**|`md5`| Function to use for calculating hashes, as provided by [hashlib](https://docs.python.org/3/library/hashlib.html){target="_blank" rel="nofollow"} in the standard library. |
|**event_key_jmespath**|`""`| JMESPath expression to extract the idempotency key from the event record using [built-in functions](./jmespath_functions.md#built-in-jmespath-functions){target="_blank"} |
734
+
|**payload_validation_jmespath**|`""`| JMESPath expression to validate whether certain parameters have changed in the event while the event payload |
735
+
|**raise_on_no_idempotency_key**|`False`| Raise exception if no idempotency key was found in the request |
736
+
|**expires_after_seconds**| 3600 | The number of seconds to wait before a record is expired |
737
+
|**use_local_cache**|`False`| Whether to locally cache idempotency results |
738
+
|**local_cache_max_items**| 256 | Max number of items to store in local cache |
739
+
|**hash_function**|`md5`| Function to use for calculating hashes, as provided by [hashlib](https://docs.python.org/3/library/hashlib.html){target="_blank" rel="nofollow"} in the standard library. |
745
740
|**response_hook**|`None`| Function to use for processing the stored Idempotent response. This function hook is called when an existing idempotent response is found. See [Manipulating The Idempotent Response](idempotency.md#manipulating-the-idempotent-response)|
746
741
747
742
### Handling concurrent executions with the same payload
0 commit comments