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
+27-25Lines changed: 27 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -140,7 +140,7 @@ You can quickly start by configuring `Idempotency` and using it with the `Idempo
140
140
!!! warning "Important"
141
141
Initialization and configuration of the `Idempotency` must be performed outside the handler, preferably in the constructor.
142
142
143
-
```csharp hl_lines="4 7"
143
+
```csharp hl_lines="5 8"
144
144
public class Function
145
145
{
146
146
public Function()
@@ -167,7 +167,7 @@ When using `Idempotent` attribute on another method, you must tell which paramet
167
167
168
168
!!! info "The parameter must be serializable in JSON. We use `System.Text.Json` internally to (de)serialize objects"
169
169
170
-
```csharp hl_lines="4 13-14"
170
+
```csharp hl_lines="5 14-15"
171
171
public class Function
172
172
{
173
173
public Function()
@@ -211,7 +211,7 @@ If we were to treat the entire request as our idempotency key, a simple HTTP hea
211
211
212
212
=== "Payment function"
213
213
214
-
```csharp hl_lines="3"
214
+
```csharp hl_lines="4"
215
215
Idempotency.Configure(builder =>
216
216
builder
217
217
.WithOptions(optionsBuilder =>
@@ -221,7 +221,7 @@ If we were to treat the entire request as our idempotency key, a simple HTTP hea
221
221
222
222
=== "Sample event"
223
223
224
-
```json hl_lines="27"
224
+
```json hl_lines="28"
225
225
{
226
226
"version": "2.0",
227
227
"routeKey": "ANY /createpayment",
@@ -257,25 +257,25 @@ If we were to treat the entire request as our idempotency key, a simple HTTP hea
257
257
### Lambda timeouts
258
258
259
259
???+ note
260
-
This is automatically done when you decorate your Lambda handler with [Idempotent attribute](#idempotent-attribute).
261
-
262
-
To prevent against extended failed retries when a [Lambda function times out](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-verify-invocation-timeouts/){target="_blank"},
263
-
Powertools for AWS Lambda (.NET) calculates and includes the remaining invocation available time as part of the idempotency record.
260
+
This is automatically done when you decorate your Lambda handler with [Idempotent attribute](#idempotent-attribute).
261
+
262
+
To prevent against extended failed retries when a [Lambda function times out](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-verify-invocation-timeouts/){target="_blank"},
263
+
Powertools for AWS Lambda (.NET) calculates and includes the remaining invocation available time as part of the idempotency record.
264
264
265
265
???+ example
266
-
If a second invocation happens **after** this timestamp, and the record is marked as `INPROGRESS`, we will execute the invocation again as if it was in the `EXPIRED` state (e.g, `Expired` field elapsed).
266
+
If a second invocation happens **after** this timestamp, and the record is marked as `INPROGRESS`, we will execute the invocation again as if it was in the `EXPIRED` state (e.g, `Expired` field elapsed).
267
267
268
268
This means that if an invocation expired during execution, it will be quickly executed again on the next retry.
269
269
270
270
???+ important
271
-
If you are only using the [Idempotent attribute](#Idempotent-attribute-on-another-method) to guard isolated parts of your code,
272
-
you must use `RegisterLambdaContext` available in the `Idempotency` static class to benefit from this protection.
271
+
If you are only using the [Idempotent attribute](#Idempotent-attribute-on-another-method) to guard isolated parts of your code,
272
+
you must use `RegisterLambdaContext` available in the `Idempotency` static class to benefit from this protection.
273
273
274
274
Here is an example on how you register the Lambda context in your handler:
275
275
276
276
=== "Registering the Lambda context"
277
277
278
-
```csharp hl_lines="9" title="Registering the Lambda context"
278
+
```csharp hl_lines="10" title="Registering the Lambda context"
279
279
public class Function
280
280
{
281
281
public Function()
@@ -331,7 +331,7 @@ If an Exception is raised _outside_ the scope of the decorated method and after
331
331
332
332
=== "Handling exceptions"
333
333
334
-
```csharp hl_lines="2-4 8-10" title="Exception not affecting idempotency record sample"
334
+
```csharp hl_lines="10-12 16-18 21" title="Exception not affecting idempotency record sample"
335
335
public class Function
336
336
{
337
337
public Function()
@@ -675,7 +675,7 @@ With **`PayloadValidationJMESPath`**, you can provide an additional JMESPath exp
675
675
676
676
=== "Function.cs"
677
677
678
-
```csharp
678
+
```csharp hl_lines="6"
679
679
Idempotency.Configure(builder =>
680
680
builder
681
681
.WithOptions(optionsBuilder =>
@@ -730,7 +730,7 @@ This means that we will throw **`IdempotencyKeyException`** if the evaluation of
730
730
731
731
=== "Function.cs"
732
732
733
-
```csharp
733
+
```csharp hl_lines="9"
734
734
public App()
735
735
{
736
736
Idempotency.Configure(builder =>
@@ -752,7 +752,7 @@ This means that we will throw **`IdempotencyKeyException`** if the evaluation of
752
752
753
753
=== "Success Event"
754
754
755
-
```json
755
+
```json hl_lines="6"
756
756
{
757
757
"user": {
758
758
"uid": "BB0D045C-8878-40C8-889E-38B3CB0A61B1",
@@ -782,7 +782,7 @@ When creating the `DynamoDBPersistenceStore`, you can set a custom [`AmazonDynam
782
782
783
783
=== "Custom AmazonDynamoDBClient"
784
784
785
-
```csharp
785
+
```csharp hl_lines="3 9"
786
786
public Function()
787
787
{
788
788
AmazonDynamoDBClient customClient = new AmazonDynamoDBClient(RegionEndpoint.APSouth1);
@@ -804,14 +804,16 @@ With this setting, we will save the idempotency key in the sort key instead of t
804
804
805
805
You can optionally set a static value for the partition key using the `StaticPkValue` parameter.
806
806
807
-
```csharp title="Reusing a DynamoDB table that uses a composite primary key"
808
-
Idempotency.Configure(builder=>
809
-
builder.UseDynamoDb(storeBuilder=>
810
-
storeBuilder.
811
-
WithTableName("TABLE_NAME")
812
-
.WithSortKeyAttr("sort_key")
813
-
));
814
-
```
807
+
=== "Reusing a DynamoDB table that uses a composite primary key"
0 commit comments