Skip to content

Commit e241ca9

Browse files
authored
Merge pull request #400 from aws-powertools/hjgraca-fix-idempotency-docs
2 parents 69865aa + d1fdb7b commit e241ca9

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

docs/utilities/idempotency.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ You can quickly start by configuring `Idempotency` and using it with the `Idempo
140140
!!! warning "Important"
141141
Initialization and configuration of the `Idempotency` must be performed outside the handler, preferably in the constructor.
142142

143-
```csharp hl_lines="4 7"
143+
```csharp hl_lines="5 8"
144144
public class Function
145145
{
146146
public Function()
@@ -167,7 +167,7 @@ When using `Idempotent` attribute on another method, you must tell which paramet
167167

168168
!!! info "The parameter must be serializable in JSON. We use `System.Text.Json` internally to (de)serialize objects"
169169

170-
```csharp hl_lines="4 13-14"
170+
```csharp hl_lines="5 14-15"
171171
public class Function
172172
{
173173
public Function()
@@ -211,7 +211,7 @@ If we were to treat the entire request as our idempotency key, a simple HTTP hea
211211

212212
=== "Payment function"
213213

214-
```csharp hl_lines="3"
214+
```csharp hl_lines="4"
215215
Idempotency.Configure(builder =>
216216
builder
217217
.WithOptions(optionsBuilder =>
@@ -221,7 +221,7 @@ If we were to treat the entire request as our idempotency key, a simple HTTP hea
221221

222222
=== "Sample event"
223223

224-
```json hl_lines="27"
224+
```json hl_lines="28"
225225
{
226226
"version": "2.0",
227227
"routeKey": "ANY /createpayment",
@@ -257,25 +257,25 @@ If we were to treat the entire request as our idempotency key, a simple HTTP hea
257257
### Lambda timeouts
258258

259259
???+ 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.
264264

265265
???+ 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).
267267

268268
This means that if an invocation expired during execution, it will be quickly executed again on the next retry.
269269

270270
???+ 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.
273273

274274
Here is an example on how you register the Lambda context in your handler:
275275

276276
=== "Registering the Lambda context"
277277

278-
```csharp hl_lines="9" title="Registering the Lambda context"
278+
```csharp hl_lines="10" title="Registering the Lambda context"
279279
public class Function
280280
{
281281
public Function()
@@ -331,7 +331,7 @@ If an Exception is raised _outside_ the scope of the decorated method and after
331331

332332
=== "Handling exceptions"
333333

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"
335335
public class Function
336336
{
337337
public Function()
@@ -675,7 +675,7 @@ With **`PayloadValidationJMESPath`**, you can provide an additional JMESPath exp
675675

676676
=== "Function.cs"
677677

678-
```csharp
678+
```csharp hl_lines="6"
679679
Idempotency.Configure(builder =>
680680
builder
681681
.WithOptions(optionsBuilder =>
@@ -730,7 +730,7 @@ This means that we will throw **`IdempotencyKeyException`** if the evaluation of
730730

731731
=== "Function.cs"
732732

733-
```csharp
733+
```csharp hl_lines="9"
734734
public App()
735735
{
736736
Idempotency.Configure(builder =>
@@ -752,7 +752,7 @@ This means that we will throw **`IdempotencyKeyException`** if the evaluation of
752752

753753
=== "Success Event"
754754

755-
```json
755+
```json hl_lines="6"
756756
{
757757
"user": {
758758
"uid": "BB0D045C-8878-40C8-889E-38B3CB0A61B1",
@@ -782,7 +782,7 @@ When creating the `DynamoDBPersistenceStore`, you can set a custom [`AmazonDynam
782782

783783
=== "Custom AmazonDynamoDBClient"
784784

785-
```csharp
785+
```csharp hl_lines="3 9"
786786
public Function()
787787
{
788788
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
804804

805805
You can optionally set a static value for the partition key using the `StaticPkValue` parameter.
806806

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"
808+
809+
```csharp hl_lines="5"
810+
Idempotency.Configure(builder =>
811+
builder.UseDynamoDb(storeBuilder =>
812+
storeBuilder.
813+
WithTableName("TABLE_NAME")
814+
.WithSortKeyAttr("sort_key")
815+
));
816+
```
815817

816818
Data would then be stored in DynamoDB like this:
817819

mkdocs.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ theme:
2626
palette:
2727
- scheme: default
2828
primary: blue
29-
accent: deep orange
29+
accent: deep blue
3030
toggle:
3131
icon: material/toggle-switch-off-outline
3232
name: Switch to dark mode
3333
- scheme: slate
3434
primary: blue
35-
accent: orange
35+
accent: deep blue
3636
toggle:
3737
icon: material/toggle-switch
3838
name: Switch to light mode
@@ -69,9 +69,15 @@ markdown_extensions:
6969
permalink: true
7070
toc_depth: 4
7171
- attr_list
72-
- pymdownx.emoji
72+
- pymdownx.emoji:
73+
emoji_index: !!python/name:materialx.emoji.twemoji
74+
emoji_generator: !!python/name:materialx.emoji.to_svg
7375
- pymdownx.inlinehilite
74-
- pymdownx.superfences
76+
- pymdownx.superfences:
77+
custom_fences:
78+
- name: mermaid
79+
class: mermaid
80+
format: !!python/name:pymdownx.superfences.fence_code_format
7581

7682
copyright: Copyright © 2023 Amazon Web Services
7783

@@ -88,3 +94,9 @@ extra_javascript:
8894
extra:
8995
version:
9096
provider: mike
97+
social:
98+
- icon: fontawesome/brands/github
99+
link: https://github.com/aws-powertools/powertools-lambda-dotnet
100+
- icon: fontawesome/brands/discord
101+
link: https://discord.gg/B8zZKbbyET
102+
name: Join our Discord Server!

0 commit comments

Comments
 (0)