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
Copy file name to clipboardExpand all lines: docs/utilities/idempotency.md
+24-13
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ classDiagram
52
52
53
53
## Getting started
54
54
55
-
We use Amazon DynamoDB as the default persistence layer in the documentation. If you prefer Redis, you can learn more from [this section](#redis-as-persistent-storage-layer-provider).
55
+
We use Amazon DynamoDB as the default persistence layer in the documentation. If you prefer Redis, you can learn more from [this section](#redis-cluster).
56
56
57
57
### IAM Permissions
58
58
@@ -80,7 +80,7 @@ To start, you'll need:
80
80
81
81
---
82
82
83
-
[Amazon DynamoDB](#dynamodb-table) or [Redis](#redis-as-persistent-storage-layer-provider)
83
+
[Amazon DynamoDB](#dynamodb-table) or [Redis](#redis-cluster)
@@ -126,7 +126,7 @@ Note that `fn_qualified_name` means the [qualified name for classes and function
126
126
127
127
##### Limitations
128
128
129
-
***DynamoDB restricts [item sizes to 400KB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-items){target="_blank"}**. This means that if your annotated function's response must be smaller than 400KB, otherwise your function will fail. Consider [Redis](#redis-as-persistent-storage-layer-provider) as an alternative.
129
+
***DynamoDB restricts [item sizes to 400KB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-items){target="_blank"}**. This means that if your annotated function's response must be smaller than 400KB, otherwise your function will fail. Consider [Redis](#redis-cluster) as an alternative.
130
130
131
131
***Expect 2 WCU per non-idempotent call**. During the first invocation, we use `PutItem` for locking and `UpdateItem` for completion. Consider reviewing [DynamoDB pricing documentation](https://aws.amazon.com/dynamodb/pricing/){target="_blank"} to estimate cost.
132
132
@@ -138,19 +138,34 @@ Note that `fn_qualified_name` means the [qualified name for classes and function
138
138
139
139
##### Constraints
140
140
141
-
If you'd like to use Redis, please [read here](#redis-as-persistent-storage-layer-provider) on how to setup and access secrets/SSL certs.
141
+
##### Redis IaC examples
142
+
143
+
=== "AWS CloudFormation example"
144
+
145
+
!!! tip inline end "Prefer AWS Console/CLI?"
146
+
147
+
Follow 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/)
1. Replace the Security Group ID and Subnet ID to match your VPC settings.
154
+
2. Replace the Security Group ID and Subnet ID to match your VPC settings.
155
+
156
+
Once setup, you can find a quick start and advanced examples for Redis in [the persistent layers section](#redispersistencelayer).
142
157
143
158
<!-- markdownlint-enable MD013 -->
144
159
145
160
### Idempotent decorator
146
161
147
162
For simple use cases, you can use the `idempotent` decorator on your Lambda handler function.
148
163
149
-
It will treat the entire event as an idempotency key. That is, the same event will return the previously stored result within a [configurable time window](#expiring-idempotency-records)_(1 hour, by default)_.
164
+
It will treat the entire event as an idempotency key. That is, the same event will return the previously stored result within a [configurable time window](#adjusting-expiration-window)_(1 hour, by default)_.
150
165
151
166
=== "Idempotent decorator"
152
167
153
-
!!! tip "You can also choose [one or more fields](#choosing-a-payload-subset-for-idempotency) as an idempotency key."
168
+
!!! tip "You can also choose [one or more fields](#choosing-a-payload-subset) as an idempotency key."
@@ -337,7 +352,7 @@ You can change this expiration window with the **`expires_after_seconds`** param
337
352
338
353
!!! note "You can skip this section if you are using the [`@idempotent` decorator](#idempotent-decorator)"
339
354
340
-
By default, we protect against [concurrent executions](#handling-concurrent-executions-with-the-same-payload) with the same payload using a locking mechanism. However, if your Lambda function times out before completing the first invocation it will only accept the same request when the [idempotency record expire](#expiring-idempotency-records).
355
+
By default, we protect against [concurrent executions](#handling-concurrent-executions-with-the-same-payload) with the same payload using a locking mechanism. However, if your Lambda function times out before completing the first invocation it will only accept the same request when the [idempotency record expire](#adjusting-expiration-window).
341
356
342
357
To prevent extended failures, use **`register_lambda_context`** function from your idempotency config to calculate and include the remaining invocation time in your idempotency record.
343
358
@@ -502,7 +517,7 @@ You can can easily integrate with [Batch](batch.md){target="_blank"} using the [
502
517
???+ "Choosing an unique batch record attribute"
503
518
In this example, we choose `messageId` as our idempotency key since we know it'll be unique.
504
519
505
-
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.
520
+
Depending on your use case, it might be more accurate [to choose another field](#choosing-a-payload-subset) your producer intentionally set to define uniqueness.
506
521
507
522
=== "Integration with Batch Processor"
508
523
@@ -951,10 +966,6 @@ When using response hooks to manipulate returned data from idempotent operations
951
966
952
967
## Compatibility with other utilities
953
968
954
-
### Batch
955
-
956
-
See [Batch integration](#batch-integration) above.
957
-
958
969
### JSON Schema Validation
959
970
960
971
The idempotency utility can be used with the `validator` decorator. Ensure that idempotency is the innermost decorator.
@@ -965,7 +976,7 @@ The idempotency utility can be used with the `validator` decorator. Ensure that
965
976
966
977
Make sure to account for this behavior, if you set the `event_key_jmespath`.
967
978
968
-
=== "Using Idempotency with JSONSchema Validation utility"
0 commit comments