Skip to content

Commit 362c272

Browse files
authored
Merge branch 'develop' into release(1.20)-update-versions
2 parents 112f2db + fb7e6c3 commit 362c272

File tree

63 files changed

+2010
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2010
-308
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PROCESS
22
#
3-
# 1. Deploy the core and AOT stacks using the infra deployment workflow.
3+
# 1. Deploy the E2E stacks using the infra deployment workflow for non-aot and aot.
44
# 2. Run the E2E tests after the infrastructure is deployed.
55
# 3. Destroy the CDK stacks after the tests are completed.
66

@@ -50,10 +50,10 @@ jobs:
5050
- name: Install AWS Lambda .NET CLI Tools
5151
run: dotnet tool install -g Amazon.Lambda.Tools
5252

53-
- name: Deploy Core Stack
53+
- name: Deploy Stack
5454
run: |
5555
cd libraries/tests/e2e/infra
56-
cdk deploy --require-approval never
56+
cdk deploy --all --require-approval never
5757
5858
deploy-aot-stack:
5959
strategy:
@@ -90,11 +90,15 @@ jobs:
9090
- name: Deploy AOT Stack
9191
run: |
9292
cd libraries/tests/e2e/infra-aot
93-
cdk deploy -c architecture=${{ matrix.arch }} --require-approval never
93+
cdk deploy --all -c architecture=${{ matrix.arch }} --require-approval never
9494
9595
run-tests:
96+
strategy:
97+
matrix:
98+
utility: [core, idempotency]
9699
runs-on: ubuntu-latest
97100
needs: [deploy-stack,deploy-aot-stack]
101+
98102
steps:
99103
- name: Checkout code
100104
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
@@ -111,14 +115,14 @@ jobs:
111115
with:
112116
dotnet-version: '8.x'
113117

114-
- name: Run Core Tests
118+
- name: Run Tests
115119
run: |
116-
cd libraries/tests/e2e/functions/core
120+
cd libraries/tests/e2e/functions/${{ matrix.utility }}
117121
dotnet test --filter Category!=AOT
118122
119-
- name: Run Core AOT Tests
123+
- name: Run AOT Tests
120124
run: |
121-
cd libraries/tests/e2e/functions/core
125+
cd libraries/tests/e2e/functions/${{ matrix.utility }}
122126
dotnet test --filter Category=AOT
123127
124128
destroy-stack:
@@ -142,10 +146,10 @@ jobs:
142146
- name: Install AWS Lambda .NET CLI Tools
143147
run: dotnet tool install -g Amazon.Lambda.Tools
144148

145-
- name: Destroy Core Stack
149+
- name: Destroy Stack
146150
run: |
147151
cd libraries/tests/e2e/infra
148-
cdk destroy --force
152+
cdk destroy --all --force
149153
150154
destroy-aot-stack:
151155
strategy:
@@ -176,8 +180,8 @@ jobs:
176180
- name: Install AWS Lambda .NET CLI Tools
177181
run: dotnet tool install -g Amazon.Lambda.Tools
178182

179-
- name: Destroy arm64 AOT Core Stack
183+
- name: Destroy arm64 AOT Stack
180184
run: |
181185
cd libraries/tests/e2e/infra-aot
182-
cdk destroy -c architecture=${{ matrix.arch }} --force
186+
cdk destroy --all -c architecture=${{ matrix.arch }} --force
183187

docs/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# v9.1.18
2-
FROM squidfunk/mkdocs-material@sha256:471695f3e611d9858788ac04e4daa9af961ccab73f1c0f545e90f8cc5d4268b8
2+
FROM squidfunk/mkdocs-material@sha256:7e841df1cfb6c8c4ff0968f2cfe55127fb1a2f5614e1c9bc23cbc11fe4c96644
33
RUN pip install mkdocs-git-revision-date-plugin

docs/utilities/idempotency.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The idempotency utility provides a simple solution to convert your Lambda functi
1414
* Select a subset of the event as the idempotency key using [JMESPath](https://jmespath.org/) expressions
1515
* Set a time window in which records with the same payload should be considered duplicates
1616
* Expires in-progress executions if the Lambda function times out halfway through
17+
* Ahead-of-Time compilation to native code support [AOT](https://docs.aws.amazon.com/lambda/latest/dg/dotnet-native-aot.html) from version 1.3.0
1718

1819
## Terminology
1920

@@ -821,10 +822,76 @@ Data would then be stored in DynamoDB like this:
821822
| idempotency#MyLambdaFunction | 2b2cdb5f86361e97b4383087c1ffdf27 | 1636549571 | COMPLETED | {"id": 527212, "message": "success"} |
822823
| idempotency#MyLambdaFunction | f091d2527ad1c78f05d54cc3f363be80 | 1636549585 | IN_PROGRESS | |
823824

825+
826+
## AOT Support
827+
828+
Native AOT trims your application code as part of the compilation to ensure that the binary is as small as possible. .NET 8 for Lambda provides improved trimming support compared to previous versions of .NET.
829+
830+
### WithJsonSerializationContext()
831+
832+
To use Idempotency utility with AOT support you first need to add `WithJsonSerializationContext()` to your `Idempotency` configuration.
833+
834+
This ensures that when serializing your payload, the utility uses the correct serialization context.
835+
836+
In the example below, we use the default `LambdaFunctionJsonSerializerContext`:
837+
838+
```csharp
839+
Idempotency.Configure(builder =>
840+
builder.WithJsonSerializationContext(LambdaFunctionJsonSerializerContext.Default)));
841+
842+
```
843+
844+
Full example:
845+
846+
```csharp hl_lines="8"
847+
public static class Function
848+
{
849+
private static async Task Main()
850+
{
851+
var tableName = Environment.GetEnvironmentVariable("IDEMPOTENCY_TABLE_NAME");
852+
Idempotency.Configure(builder =>
853+
builder
854+
.WithJsonSerializationContext(LambdaFunctionJsonSerializerContext.Default)
855+
.WithOptions(optionsBuilder => optionsBuilder
856+
.WithExpiration(TimeSpan.FromHours(1)))
857+
.UseDynamoDb(storeBuilder => storeBuilder
858+
.WithTableName(tableName)
859+
));
860+
861+
Func<APIGatewayProxyRequest, ILambdaContext, APIGatewayProxyResponse> handler = FunctionHandler;
862+
await LambdaBootstrapBuilder.Create(handler,
863+
new SourceGeneratorLambdaJsonSerializer<LambdaFunctionJsonSerializerContext>())
864+
.Build()
865+
.RunAsync();
866+
}
867+
868+
[Idempotent]
869+
public static APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest apigwProxyEvent,
870+
ILambdaContext context)
871+
{
872+
return new APIGatewayProxyResponse
873+
{
874+
Body = JsonSerializer.Serialize(response, typeof(Response), LambdaFunctionJsonSerializerContext.Default),
875+
StatusCode = 200,
876+
Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
877+
};
878+
}
879+
}
880+
881+
[JsonSerializable(typeof(APIGatewayProxyRequest))]
882+
[JsonSerializable(typeof(APIGatewayProxyResponse))]
883+
[JsonSerializable(typeof(Response))]
884+
public partial class LambdaFunctionJsonSerializerContext : JsonSerializerContext
885+
{
886+
}
887+
```
888+
824889
## Testing your code
825890

826891
The idempotency utility provides several routes to test your code.
827892

893+
You can check our Integration tests which use [TestContainers](https://testcontainers.com/modules/dynamodb/){:target="_blank"} with a local DynamoDB instance to test the idempotency utility. Or our end-to-end tests which use the AWS SDK to interact with a real DynamoDB table.
894+
828895
### Disabling the idempotency utility
829896
When testing your code, you may wish to disable the idempotency logic altogether and focus on testing your business logic. To do this, you can set the environment variable `POWERTOOLS_IDEMPOTENCY_DISABLED` to true.
830897

libraries/AWS.Lambda.Powertools.sln

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ EndProject
4747
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infra", "Infra", "{93DEAC72-245F-4FC9-A7B5-DAE7EF7E1AB7}"
4848
EndProject
4949
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Functions", "Functions", "{CDAE55EB-9438-4F54-B7ED-931D64324D5F}"
50+
ProjectSection(SolutionItems) = preProject
51+
tests\e2e\functions\payload.json = tests\e2e\functions\payload.json
52+
EndProjectSection
5053
EndProject
5154
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infra", "tests\e2e\infra\Infra.csproj", "{AA532674-A61C-41E6-8F9A-ED53D79AF1EC}"
5255
EndProject
5356
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{AAFA39E9-66A3-4B9A-AFE9-EAF74A85A7F0}"
54-
ProjectSection(SolutionItems) = preProject
55-
tests\e2e\functions\core\payload.json = tests\e2e\functions\core\payload.json
56-
EndProjectSection
5757
EndProject
5858
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils", "tests\e2e\functions\TestUtils\TestUtils.csproj", "{3C6162D7-0162-4BC2-BBF5-0554539A81CD}"
5959
EndProject
@@ -83,6 +83,20 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOT-Function", "tests\e2e\f
8383
EndProject
8484
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InfraAot", "tests\e2e\infra-aot\InfraAot.csproj", "{24AC34AD-AEC9-4CFB-BB01-C3C81938AB95}"
8585
EndProject
86+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InfraShared", "tests\e2e\InfraShared\InfraShared.csproj", "{D303B458-9D84-4DDF-8781-2C0211672329}"
87+
EndProject
88+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Idempotency", "Idempotency", "{FB2C7DA3-6FCE-429D-86F9-5775D0231EC6}"
89+
EndProject
90+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Function", "tests\e2e\functions\idempotency\Function\src\Function\Function.csproj", "{9AF99F6D-E8E7-443F-A965-D55B8E388836}"
91+
EndProject
92+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Function.Tests", "tests\e2e\functions\idempotency\Function\test\Function.Tests\Function.Tests.csproj", "{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}"
93+
EndProject
94+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOT-FunctionPayloadSubsetTest", "tests\e2e\functions\idempotency\AOT-Function\src\AOT-FunctionPayloadSubsetTest\AOT-FunctionPayloadSubsetTest.csproj", "{ACA789EA-BD38-490B-A7F8-6A3A86985025}"
95+
EndProject
96+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOT-FunctionHandlerTest", "tests\e2e\functions\idempotency\AOT-Function\src\AOT-FunctionHandlerTest\AOT-FunctionHandlerTest.csproj", "{E71C48D2-AD56-4177-BBD7-6BB859A40C92}"
97+
EndProject
98+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOT-FunctionMethodAttributeTest", "tests\e2e\functions\idempotency\AOT-Function\src\AOT-FunctionMethodAttributeTest\AOT-FunctionMethodAttributeTest.csproj", "{CC8CFF43-DC72-464C-A42D-55E023DE8500}"
99+
EndProject
86100
Global
87101
GlobalSection(SolutionConfigurationPlatforms) = preSolution
88102
Debug|Any CPU = Debug|Any CPU
@@ -432,6 +446,78 @@ Global
432446
{24AC34AD-AEC9-4CFB-BB01-C3C81938AB95}.Release|x64.Build.0 = Release|Any CPU
433447
{24AC34AD-AEC9-4CFB-BB01-C3C81938AB95}.Release|x86.ActiveCfg = Release|Any CPU
434448
{24AC34AD-AEC9-4CFB-BB01-C3C81938AB95}.Release|x86.Build.0 = Release|Any CPU
449+
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
450+
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|Any CPU.Build.0 = Debug|Any CPU
451+
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|x64.ActiveCfg = Debug|Any CPU
452+
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|x64.Build.0 = Debug|Any CPU
453+
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|x86.ActiveCfg = Debug|Any CPU
454+
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|x86.Build.0 = Debug|Any CPU
455+
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|Any CPU.ActiveCfg = Release|Any CPU
456+
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|Any CPU.Build.0 = Release|Any CPU
457+
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|x64.ActiveCfg = Release|Any CPU
458+
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|x64.Build.0 = Release|Any CPU
459+
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|x86.ActiveCfg = Release|Any CPU
460+
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|x86.Build.0 = Release|Any CPU
461+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
462+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|Any CPU.Build.0 = Debug|Any CPU
463+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|x64.ActiveCfg = Debug|Any CPU
464+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|x64.Build.0 = Debug|Any CPU
465+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|x86.ActiveCfg = Debug|Any CPU
466+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|x86.Build.0 = Debug|Any CPU
467+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|Any CPU.ActiveCfg = Release|Any CPU
468+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|Any CPU.Build.0 = Release|Any CPU
469+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|x64.ActiveCfg = Release|Any CPU
470+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|x64.Build.0 = Release|Any CPU
471+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|x86.ActiveCfg = Release|Any CPU
472+
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|x86.Build.0 = Release|Any CPU
473+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
474+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
475+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|x64.ActiveCfg = Debug|Any CPU
476+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|x64.Build.0 = Debug|Any CPU
477+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|x86.ActiveCfg = Debug|Any CPU
478+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|x86.Build.0 = Debug|Any CPU
479+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
480+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|Any CPU.Build.0 = Release|Any CPU
481+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|x64.ActiveCfg = Release|Any CPU
482+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|x64.Build.0 = Release|Any CPU
483+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|x86.ActiveCfg = Release|Any CPU
484+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|x86.Build.0 = Release|Any CPU
485+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
486+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Debug|Any CPU.Build.0 = Debug|Any CPU
487+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Debug|x64.ActiveCfg = Debug|Any CPU
488+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Debug|x64.Build.0 = Debug|Any CPU
489+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Debug|x86.ActiveCfg = Debug|Any CPU
490+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Debug|x86.Build.0 = Debug|Any CPU
491+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Release|Any CPU.ActiveCfg = Release|Any CPU
492+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Release|Any CPU.Build.0 = Release|Any CPU
493+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Release|x64.ActiveCfg = Release|Any CPU
494+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Release|x64.Build.0 = Release|Any CPU
495+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Release|x86.ActiveCfg = Release|Any CPU
496+
{ACA789EA-BD38-490B-A7F8-6A3A86985025}.Release|x86.Build.0 = Release|Any CPU
497+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
498+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Debug|Any CPU.Build.0 = Debug|Any CPU
499+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Debug|x64.ActiveCfg = Debug|Any CPU
500+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Debug|x64.Build.0 = Debug|Any CPU
501+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Debug|x86.ActiveCfg = Debug|Any CPU
502+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Debug|x86.Build.0 = Debug|Any CPU
503+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Release|Any CPU.ActiveCfg = Release|Any CPU
504+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Release|Any CPU.Build.0 = Release|Any CPU
505+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Release|x64.ActiveCfg = Release|Any CPU
506+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Release|x64.Build.0 = Release|Any CPU
507+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Release|x86.ActiveCfg = Release|Any CPU
508+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92}.Release|x86.Build.0 = Release|Any CPU
509+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
510+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Debug|Any CPU.Build.0 = Debug|Any CPU
511+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Debug|x64.ActiveCfg = Debug|Any CPU
512+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Debug|x64.Build.0 = Debug|Any CPU
513+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Debug|x86.ActiveCfg = Debug|Any CPU
514+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Debug|x86.Build.0 = Debug|Any CPU
515+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Release|Any CPU.ActiveCfg = Release|Any CPU
516+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Release|Any CPU.Build.0 = Release|Any CPU
517+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Release|x64.ActiveCfg = Release|Any CPU
518+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Release|x64.Build.0 = Release|Any CPU
519+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Release|x86.ActiveCfg = Release|Any CPU
520+
{CC8CFF43-DC72-464C-A42D-55E023DE8500}.Release|x86.Build.0 = Release|Any CPU
435521
EndGlobalSection
436522

437523
GlobalSection(NestedProjects) = preSolution
@@ -470,5 +556,12 @@ Global
470556
{8DDAFE37-ED59-4710-9415-8EBA44CC6437} = {3C9FA701-31FF-4747-B324-E0D252EAFD63}
471557
{8DDED681-AE8D-45EB-A22E-2FFB88620F9B} = {3C9FA701-31FF-4747-B324-E0D252EAFD63}
472558
{24AC34AD-AEC9-4CFB-BB01-C3C81938AB95} = {93DEAC72-245F-4FC9-A7B5-DAE7EF7E1AB7}
559+
{D303B458-9D84-4DDF-8781-2C0211672329} = {93DEAC72-245F-4FC9-A7B5-DAE7EF7E1AB7}
560+
{FB2C7DA3-6FCE-429D-86F9-5775D0231EC6} = {CDAE55EB-9438-4F54-B7ED-931D64324D5F}
561+
{9AF99F6D-E8E7-443F-A965-D55B8E388836} = {FB2C7DA3-6FCE-429D-86F9-5775D0231EC6}
562+
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC} = {FB2C7DA3-6FCE-429D-86F9-5775D0231EC6}
563+
{ACA789EA-BD38-490B-A7F8-6A3A86985025} = {FB2C7DA3-6FCE-429D-86F9-5775D0231EC6}
564+
{E71C48D2-AD56-4177-BBD7-6BB859A40C92} = {FB2C7DA3-6FCE-429D-86F9-5775D0231EC6}
565+
{CC8CFF43-DC72-464C-A42D-55E023DE8500} = {FB2C7DA3-6FCE-429D-86F9-5775D0231EC6}
473566
EndGlobalSection
474567
EndGlobal

libraries/src/AWS.Lambda.Powertools.Idempotency/Idempotency.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
/*
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
66
* A copy of the License is located at
7-
*
7+
*
88
* http://aws.amazon.com/apache2.0
9-
*
9+
*
1010
* or in the "license" file accompanying this file. This file is distributed
1111
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1212
* express or implied. See the License for the specific language governing
1313
* permissions and limitations under the License.
1414
*/
1515

1616
using System;
17+
using System.Text.Json.Serialization;
1718
using Amazon.Lambda.Core;
1819
using AWS.Lambda.Powertools.Common;
20+
using AWS.Lambda.Powertools.Idempotency.Internal.Serializers;
1921
using AWS.Lambda.Powertools.Idempotency.Persistence;
2022

2123
namespace AWS.Lambda.Powertools.Idempotency;
@@ -27,7 +29,7 @@ namespace AWS.Lambda.Powertools.Idempotency;
2729
/// Use it before the function handler get called.
2830
/// Example: Idempotency.Configure(builder => builder.WithPersistenceStore(...));
2931
/// </summary>
30-
public sealed class Idempotency
32+
public sealed class Idempotency
3133
{
3234
/// <summary>
3335
/// The general configurations for the idempotency
@@ -47,6 +49,7 @@ internal Idempotency(IPowertoolsConfigurations powertoolsConfigurations)
4749
{
4850
powertoolsConfigurations.SetExecutionEnvironment(this);
4951
}
52+
5053
/// <summary>
5154
/// Set Idempotency options
5255
/// </summary>
@@ -68,7 +71,7 @@ private void SetPersistenceStore(BasePersistenceStore persistenceStore)
6871
/// <summary>
6972
/// Holds the idempotency Instance:
7073
/// </summary>
71-
public static Idempotency Instance { get; } = new(PowertoolsConfigurations.Instance);
74+
internal static Idempotency Instance { get; } = new(PowertoolsConfigurations.Instance);
7275

7376
/// <summary>
7477
/// Use this method to configure persistence layer (mandatory) and idempotency options (optional)
@@ -90,7 +93,7 @@ public static void Configure(Action<IdempotencyBuilder> configurationAction)
9093
/// Holds ILambdaContext
9194
/// </summary>
9295
public ILambdaContext LambdaContext { get; private set; }
93-
96+
9497
/// <summary>
9598
/// Can be used in a method which is not the handler to capture the Lambda context,
9699
/// to calculate the remaining time before the invocation times out.
@@ -177,5 +180,18 @@ public IdempotencyBuilder WithOptions(IdempotencyOptions options)
177180
Options = options;
178181
return this;
179182
}
183+
184+
#if NET8_0_OR_GREATER
185+
/// <summary>
186+
/// Set Customer JsonSerializerContext to append to IdempotencySerializationContext
187+
/// </summary>
188+
/// <param name="context"></param>
189+
/// <returns>IdempotencyBuilder</returns>
190+
public IdempotencyBuilder WithJsonSerializationContext(JsonSerializerContext context)
191+
{
192+
IdempotencySerializer.AddTypeInfoResolver(context);
193+
return this;
194+
}
195+
#endif
180196
}
181197
}

0 commit comments

Comments
 (0)