Skip to content

Commit dba5e90

Browse files
authored
Merge pull request #163 from hossambarakat/feature/idempotency
Great work!!
2 parents 12ddf19 + 33de0e1 commit dba5e90

Some content is hidden

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

44 files changed

+4971
-3
lines changed

docs/core/idempotency.md

Lines changed: 431 additions & 0 deletions
Large diffs are not rendered by default.

libraries/AWS.Lambda.Powertools.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.Traci
2323
EndProject
2424
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.Common.Tests", "tests\AWS.Lambda.Powertools.Common.Tests\AWS.Lambda.Powertools.Common.Tests.csproj", "{4EC48E6A-45B5-4E25-ABBD-C23FE2BD6E1E}"
2525
EndProject
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.Idempotency", "src\AWS.Lambda.Powertools.Idempotency\AWS.Lambda.Powertools.Idempotency.csproj", "{B7AC87DF-9705-47D9-AC00-C230E577CA5D}"
27+
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.Idempotency.Tests", "tests\AWS.Lambda.Powertools.Idempotency.Tests\AWS.Lambda.Powertools.Idempotency.Tests.csproj", "{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}"
29+
EndProject
2630
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.Parameters", "src\AWS.Lambda.Powertools.Parameters\AWS.Lambda.Powertools.Parameters.csproj", "{1ECB31E8-2EF0-41E2-8C71-CB9876D207F0}"
2731
EndProject
2832
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.Parameters.Tests", "tests\AWS.Lambda.Powertools.Parameters.Tests\AWS.Lambda.Powertools.Parameters.Tests.csproj", "{386A9769-59BF-4BE3-99D4-A9603E300729}"
@@ -136,6 +140,30 @@ Global
136140
{4EC48E6A-45B5-4E25-ABBD-C23FE2BD6E1E}.Release|x64.Build.0 = Release|Any CPU
137141
{4EC48E6A-45B5-4E25-ABBD-C23FE2BD6E1E}.Release|x86.ActiveCfg = Release|Any CPU
138142
{4EC48E6A-45B5-4E25-ABBD-C23FE2BD6E1E}.Release|x86.Build.0 = Release|Any CPU
143+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
144+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
145+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|x64.ActiveCfg = Debug|Any CPU
146+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|x64.Build.0 = Debug|Any CPU
147+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|x86.ActiveCfg = Debug|Any CPU
148+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|x86.Build.0 = Debug|Any CPU
149+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
150+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|Any CPU.Build.0 = Release|Any CPU
151+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|x64.ActiveCfg = Release|Any CPU
152+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|x64.Build.0 = Release|Any CPU
153+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|x86.ActiveCfg = Release|Any CPU
154+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|x86.Build.0 = Release|Any CPU
155+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
156+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
157+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|x64.ActiveCfg = Debug|Any CPU
158+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|x64.Build.0 = Debug|Any CPU
159+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|x86.ActiveCfg = Debug|Any CPU
160+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|x86.Build.0 = Debug|Any CPU
161+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
162+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|Any CPU.Build.0 = Release|Any CPU
163+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|x64.ActiveCfg = Release|Any CPU
164+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|x64.Build.0 = Release|Any CPU
165+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|x86.ActiveCfg = Release|Any CPU
166+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|x86.Build.0 = Release|Any CPU
139167
{1ECB31E8-2EF0-41E2-8C71-CB9876D207F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
140168
{1ECB31E8-2EF0-41E2-8C71-CB9876D207F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
141169
{1ECB31E8-2EF0-41E2-8C71-CB9876D207F0}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -173,5 +201,7 @@ Global
173201
{A040AED5-BBB8-4BFA-B2A5-BBD82817B8A5} = {1CFF5568-8486-475F-81F6-06105C437528}
174202
{1ECB31E8-2EF0-41E2-8C71-CB9876D207F0} = {73C9B1E5-3893-47E8-B373-17E5F5D7E6F5}
175203
{386A9769-59BF-4BE3-99D4-A9603E300729} = {1CFF5568-8486-475F-81F6-06105C437528}
204+
{B7AC87DF-9705-47D9-AC00-C230E577CA5D} = {73C9B1E5-3893-47E8-B373-17E5F5D7E6F5}
205+
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3} = {1CFF5568-8486-475F-81F6-06105C437528}
176206
EndGlobalSection
177207
EndGlobal

libraries/src/AWS.Lambda.Powertools.Common/Core/Constants.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,19 @@ internal static class Constants
9090
/// Constant for Powertools for AWS Lambda (.NET) feature identifier fo AWS_EXECUTION_ENV environment variable
9191
/// </summary>
9292
internal const string FeatureContextIdentifier = "PT";
93+
94+
/// <summary>
95+
/// Constant for IDEMPOTENCY_DISABLED_ENV environment variable
96+
/// </summary>
97+
internal const string IdempotencyDisabledEnv = "POWERTOOLS_IDEMPOTENCY_DISABLED";
98+
99+
/// <summary>
100+
/// Constant for AWS_REGION_ENV environment variable
101+
/// </summary>
102+
internal const string AwsRegionEnv = "AWS_REGION";
103+
104+
/// <summary>
105+
/// Constant for LAMBDA_FUNCTION_NAME_ENV environment variable
106+
/// </summary>
107+
internal const string LambdaFunctionNameEnv = "AWS_LAMBDA_FUNCTION_NAME";
93108
}

libraries/src/AWS.Lambda.Powertools.Common/Core/IPowertoolsConfigurations.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,10 @@ public interface IPowertoolsConfigurations
126126
/// </summary>
127127
/// <param name="type"></param>
128128
void SetExecutionEnvironment<T>(T type);
129+
130+
/// <summary>
131+
/// Gets a value indicating whether [Idempotency is disabled].
132+
/// </summary>
133+
/// <value><c>true</c> if [Idempotency is disabled]; otherwise, <c>false</c>.</value>
134+
bool IdempotencyDisabled { get; }
129135
}

libraries/src/AWS.Lambda.Powertools.Common/Core/PowertoolsConfigurations.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,8 @@ public void SetExecutionEnvironment<T>(T type)
190190
{
191191
_systemWrapper.SetExecutionEnvironment(type);
192192
}
193+
194+
/// <inheritdoc />
195+
public bool IdempotencyDisabled =>
196+
GetEnvironmentVariableOrDefault(Constants.IdempotencyDisabledEnv, false);
193197
}

libraries/src/AWS.Lambda.Powertools.Common/Core/PowertoolsLambdaContext.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Linq;
3-
using System.Reflection;
42

53
namespace AWS.Lambda.Powertools.Common;
64

libraries/src/AWS.Lambda.Powertools.Common/InternalsVisibleTo.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Logging")]
1919
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Metrics")]
20+
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Idempotency")]
2021
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Common.Tests")]
2122
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Tracing.Tests")]
2223
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Metrics.Tests")]
23-
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Logging.Tests")]
24+
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Logging.Tests")]
25+
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Idempotency.Tests")]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<LangVersion>default</LangVersion>
6+
<PackageId>AWS.Lambda.Powertools.Idempotency</PackageId>
7+
<Version>0.0.1</Version>
8+
<Authors>Amazon Web Services</Authors>
9+
<Company>Amazon.com, Inc</Company>
10+
<Title>AWS Lambda Powertools for .NET</Title>
11+
<Description>AWS Lambda Powertools for .NET - Idempotency package.</Description>
12+
<Copyright>Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.</Copyright>
13+
<RepositoryUrl>https://github.com/awslabs/aws-lambda-powertools-dotnet</RepositoryUrl>
14+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
15+
<PackageTags>AWS;Amazon;Lambda;Powertools</PackageTags>
16+
<PackageReadmeFile>README.md</PackageReadmeFile>
17+
<PackageIconUrl>https://sdk-for-net.amazonwebservices.com/images/AWSLogo128x128.png</PackageIconUrl>
18+
<PackageIcon>AWSLogo128x128.png</PackageIcon>
19+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
20+
<AssemblyName>AWS.Lambda.Powertools.Idempotency</AssemblyName>
21+
<RootNamespace>AWS.Lambda.Powertools.Idempotency</RootNamespace>
22+
</PropertyGroup>
23+
24+
<PropertyGroup>
25+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
26+
</PropertyGroup>
27+
28+
<ItemGroup>
29+
<None Include="README.md" Pack="true" PackagePath="\" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
34+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.103.7" />
35+
<PackageReference Include="JmesPath.Net" Version="1.0.308" />
36+
</ItemGroup>
37+
38+
<ItemGroup>
39+
<ProjectReference Include="..\AWS.Lambda.Powertools.Common\AWS.Lambda.Powertools.Common.csproj" />
40+
</ItemGroup>
41+
42+
<ItemGroup>
43+
<None Include="../../AWSLogo128x128.png" Pack="true" Visible="false" PackagePath="" />
44+
</ItemGroup>
45+
46+
</Project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
using System;
17+
18+
namespace AWS.Lambda.Powertools.Idempotency.Exceptions;
19+
20+
/// <summary>
21+
/// This exception is thrown when the same payload is sent
22+
/// while the previous one was not yet fully stored in the persistence layer (marked as COMPLETED).
23+
/// Implements the <see cref="System.Exception" />
24+
/// </summary>
25+
/// <seealso cref="System.Exception" />
26+
public class IdempotencyAlreadyInProgressException: Exception
27+
{
28+
/// <summary>
29+
/// Creates a new IdempotencyAlreadyInProgressException
30+
/// </summary>
31+
public IdempotencyAlreadyInProgressException()
32+
{
33+
}
34+
35+
/// <inheritdoc />
36+
public IdempotencyAlreadyInProgressException(string message) : base(message)
37+
{
38+
}
39+
40+
/// <inheritdoc />
41+
public IdempotencyAlreadyInProgressException(string message, Exception innerException) : base(message, innerException)
42+
{
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
using System;
17+
18+
namespace AWS.Lambda.Powertools.Idempotency.Exceptions;
19+
20+
/// <summary>
21+
/// Exception thrown when Idempotency is not well configured:
22+
/// - An annotated method does not return anything
23+
/// - An annotated method does not use Task as return value
24+
/// - An annotated method does not have parameters
25+
/// </summary>
26+
public class IdempotencyConfigurationException : Exception
27+
{
28+
/// <summary>
29+
/// Creates a new IdempotencyConfigurationException
30+
/// </summary>
31+
public IdempotencyConfigurationException()
32+
{
33+
}
34+
35+
/// <inheritdoc />
36+
public IdempotencyConfigurationException(string message) : base(message)
37+
{
38+
}
39+
40+
/// <inheritdoc />
41+
public IdempotencyConfigurationException(string message, Exception innerException) : base(message, innerException)
42+
{
43+
}
44+
}

0 commit comments

Comments
 (0)