Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Idempotency Package #163

Merged
merged 40 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
337cf1e
Add idempotency module to solution
Aug 23, 2022
89c680a
Add documentation
Aug 23, 2022
7abb323
Consistent project files
Aug 23, 2022
eee318c
Update test names to follow the convention <MethodName>_<Condition>_<…
Sep 7, 2022
97459e6
Merge branch 'develop' into feature/idempotency
Sep 7, 2022
036bb0e
Fix HashFunction reference documentation
Sep 20, 2022
483e5cc
Merge branch 'develop' into feature/idempotency
Sep 20, 2022
73af08d
Use idiomatic C# and terser configurations for Idempotency
Oct 5, 2022
5f2bf40
Add more comments and fix null reference warnings
Oct 5, 2022
127f52c
Add NullLog as default logger
Oct 5, 2022
adcbe97
Use UniversalWrapperAspect as opposed to custom IdempotentAspect
Oct 6, 2022
7e1e7ee
Add missing documentation
Oct 6, 2022
ef81092
Fix Null Reference warning
Oct 6, 2022
b86e3f1
Use Instance as property
Oct 6, 2022
432b65f
revert removed comment
Oct 6, 2022
8b0395f
Fix minor issues in documentation
Oct 7, 2022
abf4d50
Merge branch 'awslabs:develop' into feature/idempotency
hossambarakat Jan 13, 2023
82ebd43
Merge branch 'develop' of https://github.com/awslabs/aws-lambda-power…
hjgraca Apr 27, 2023
526310f
Remove references to Newtonsoft, remove testcontainers and persistenc…
hjgraca May 5, 2023
bf66bc0
fix csproj
hjgraca May 5, 2023
4a96564
Merge remote-tracking branch 'origin/develop' into feature/idempotency
hjgraca May 5, 2023
501460b
Merge remote-tracking branch 'origin/develop' into feature/idempotency
hjgraca May 17, 2023
e878f14
Merge remote-tracking branch 'origin/develop' into feature/idempotency
hjgraca May 17, 2023
03afc4d
remove null. Code updates to var. Set execution environment tests
hjgraca May 19, 2023
971bec7
Merge remote-tracking branch 'origin/develop' into feature/idempotency
hjgraca May 19, 2023
877f082
remove constructor and skip e2e tests for CI
hjgraca May 19, 2023
02590a4
update test packages. remove newtonsoft
hjgraca May 19, 2023
41a6f6f
Upgrade Amazon.Lambda.APIGatewayEvents this changed the json so needs…
hjgraca May 22, 2023
dd6521f
move constants. Enable integration tests dynamo. Code inspection fixes
hjgraca May 24, 2023
c2167a1
forgot to skip tests
hjgraca May 24, 2023
62ed433
adding integration tests. added testcontainers. refactor for single c…
hjgraca May 24, 2023
2424868
Refactor integration tests. Now all run in TestContainer
hjgraca May 25, 2023
b6b3c7f
Refactor tests. Remove direct environment check for Idempotency Disab…
hjgraca May 25, 2023
983234f
delete file
hjgraca May 25, 2023
45c746a
Refactor. Enabled Idempotency on Sync handlers. Refactor unit tests w…
hjgraca May 26, 2023
be9bcdc
Remove LogTo method, ILog and Debug logging
hjgraca May 29, 2023
3606455
Add comments to private fields and methods
hjgraca May 30, 2023
7479811
Changes from feedback
hjgraca Jun 6, 2023
ae021c6
remove todo
hjgraca Jun 7, 2023
33de0e1
Addressing analysed warnings.
hjgraca Jun 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
431 changes: 431 additions & 0 deletions docs/core/idempotency.md

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions libraries/AWS.Lambda.Powertools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.Traci
EndProject
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}"
EndProject
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}"
EndProject
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}"
EndProject
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}"
EndProject
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}"
Expand Down Expand Up @@ -136,6 +140,30 @@ Global
{4EC48E6A-45B5-4E25-ABBD-C23FE2BD6E1E}.Release|x64.Build.0 = Release|Any CPU
{4EC48E6A-45B5-4E25-ABBD-C23FE2BD6E1E}.Release|x86.ActiveCfg = Release|Any CPU
{4EC48E6A-45B5-4E25-ABBD-C23FE2BD6E1E}.Release|x86.Build.0 = Release|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|x64.ActiveCfg = Debug|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|x64.Build.0 = Debug|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|x86.ActiveCfg = Debug|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Debug|x86.Build.0 = Debug|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|Any CPU.Build.0 = Release|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|x64.ActiveCfg = Release|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|x64.Build.0 = Release|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|x86.ActiveCfg = Release|Any CPU
{B7AC87DF-9705-47D9-AC00-C230E577CA5D}.Release|x86.Build.0 = Release|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|x64.ActiveCfg = Debug|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|x64.Build.0 = Debug|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|x86.ActiveCfg = Debug|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Debug|x86.Build.0 = Debug|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|Any CPU.Build.0 = Release|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|x64.ActiveCfg = Release|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|x64.Build.0 = Release|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|x86.ActiveCfg = Release|Any CPU
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3}.Release|x86.Build.0 = Release|Any CPU
{1ECB31E8-2EF0-41E2-8C71-CB9876D207F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1ECB31E8-2EF0-41E2-8C71-CB9876D207F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1ECB31E8-2EF0-41E2-8C71-CB9876D207F0}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -173,5 +201,7 @@ Global
{A040AED5-BBB8-4BFA-B2A5-BBD82817B8A5} = {1CFF5568-8486-475F-81F6-06105C437528}
{1ECB31E8-2EF0-41E2-8C71-CB9876D207F0} = {73C9B1E5-3893-47E8-B373-17E5F5D7E6F5}
{386A9769-59BF-4BE3-99D4-A9603E300729} = {1CFF5568-8486-475F-81F6-06105C437528}
{B7AC87DF-9705-47D9-AC00-C230E577CA5D} = {73C9B1E5-3893-47E8-B373-17E5F5D7E6F5}
{3E1D77BD-70AF-4767-B00A-4A321D5AB2C3} = {1CFF5568-8486-475F-81F6-06105C437528}
EndGlobalSection
EndGlobal
15 changes: 15 additions & 0 deletions libraries/src/AWS.Lambda.Powertools.Common/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,19 @@ internal static class Constants
/// Constant for Powertools feature identifier fo AWS_EXECUTION_ENV environment variable
/// </summary>
internal const string FeatureContextIdentifier = "PT";

/// <summary>
/// Constant for IDEMPOTENCY_DISABLED_ENV environment variable
/// </summary>
internal const string IdempotencyDisabledEnv = "POWERTOOLS_IDEMPOTENCY_DISABLED";

/// <summary>
/// Constant for AWS_REGION_ENV environment variable
/// </summary>
internal const string AwsRegionEnv = "AWS_REGION";

/// <summary>
/// Constant for LAMBDA_FUNCTION_NAME_ENV environment variable
/// </summary>
internal const string LambdaFunctionNameEnv = "AWS_LAMBDA_FUNCTION_NAME";
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,10 @@ public interface IPowertoolsConfigurations
/// </summary>
/// <param name="type"></param>
void SetExecutionEnvironment<T>(T type);

/// <summary>
/// Gets a value indicating whether [Idempotency is disabled].
/// </summary>
/// <value><c>true</c> if [Idempotency is disabled]; otherwise, <c>false</c>.</value>
bool IdempotencyDisabled { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,8 @@ public void SetExecutionEnvironment<T>(T type)
{
_systemWrapper.SetExecutionEnvironment(type);
}

/// <inheritdoc />
public bool IdempotencyDisabled =>
GetEnvironmentVariableOrDefault(Constants.IdempotencyDisabledEnv, false);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Linq;
using System.Reflection;

namespace AWS.Lambda.Powertools.Common;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Logging")]
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Metrics")]
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Idempotency")]
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Common.Tests")]
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Tracing.Tests")]
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Metrics.Tests")]
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Logging.Tests")]
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Logging.Tests")]
[assembly: InternalsVisibleTo("AWS.Lambda.Powertools.Idempotency.Tests")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>default</LangVersion>
<PackageId>AWS.Lambda.Powertools.Idempotency</PackageId>
<Version>0.0.1</Version>
<Authors>Amazon Web Services</Authors>
<Company>Amazon.com, Inc</Company>
<Title>AWS Lambda Powertools for .NET</Title>
<Description>AWS Lambda Powertools for .NET - Idempotency package.</Description>
<Copyright>Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.</Copyright>
<RepositoryUrl>https://github.com/awslabs/aws-lambda-powertools-dotnet</RepositoryUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageTags>AWS;Amazon;Lambda;Powertools</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIconUrl>https://sdk-for-net.amazonwebservices.com/images/AWSLogo128x128.png</PackageIconUrl>
<PackageIcon>AWSLogo128x128.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyName>AWS.Lambda.Powertools.Idempotency</AssemblyName>
<RootNamespace>AWS.Lambda.Powertools.Idempotency</RootNamespace>
</PropertyGroup>

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.103.7" />
<PackageReference Include="JmesPath.Net" Version="1.0.308" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AWS.Lambda.Powertools.Common\AWS.Lambda.Powertools.Common.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="../../AWSLogo128x128.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using System;

namespace AWS.Lambda.Powertools.Idempotency.Exceptions;

/// <summary>
/// This exception is thrown when the same payload is sent
/// while the previous one was not yet fully stored in the persistence layer (marked as COMPLETED).
/// Implements the <see cref="System.Exception" />
/// </summary>
/// <seealso cref="System.Exception" />
public class IdempotencyAlreadyInProgressException: Exception
{
/// <summary>
/// Creates a new IdempotencyAlreadyInProgressException
/// </summary>
public IdempotencyAlreadyInProgressException()
{
}

/// <inheritdoc />
public IdempotencyAlreadyInProgressException(string message) : base(message)
{
}

/// <inheritdoc />
public IdempotencyAlreadyInProgressException(string message, Exception innerException) : base(message, innerException)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using System;

namespace AWS.Lambda.Powertools.Idempotency.Exceptions;

/// <summary>
/// Exception thrown when Idempotency is not well configured:
/// - An annotated method does not return anything
/// - An annotated method does not use Task as return value
/// - An annotated method does not have parameters
/// </summary>
public class IdempotencyConfigurationException : Exception
{
/// <summary>
/// Creates a new IdempotencyConfigurationException
/// </summary>
public IdempotencyConfigurationException()
{
}

/// <inheritdoc />
public IdempotencyConfigurationException(string message) : base(message)
{
}

/// <inheritdoc />
public IdempotencyConfigurationException(string message, Exception innerException) : base(message, innerException)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using System;

namespace AWS.Lambda.Powertools.Idempotency.Exceptions;

/// <summary>
/// Exception can happen under rare but expected cases
/// when persistent state changes in the small-time between put and get requests.
/// </summary>
public class IdempotencyInconsistentStateException : Exception
{
/// <summary>
/// Creates a new IdempotencyInconsistentStateException
/// </summary>
public IdempotencyInconsistentStateException()
{
}

/// <inheritdoc />
public IdempotencyInconsistentStateException(string message) : base(message)
{
}

/// <inheritdoc />
public IdempotencyInconsistentStateException(string message, Exception innerException) : base(message, innerException)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using System;

namespace AWS.Lambda.Powertools.Idempotency.Exceptions;

/// <summary>
/// Exception thrown when trying to store an item which already exists.
/// </summary>
public class IdempotencyItemAlreadyExistsException : Exception
{
/// <summary>
/// Creates a new IdempotencyItemAlreadyExistsException
/// </summary>
public IdempotencyItemAlreadyExistsException()
{
}

/// <inheritdoc />
public IdempotencyItemAlreadyExistsException(string message) : base(message)
{
}

/// <inheritdoc />
public IdempotencyItemAlreadyExistsException(string message, Exception innerException) : base(message, innerException)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using System;

namespace AWS.Lambda.Powertools.Idempotency.Exceptions;

/// <summary>
/// Exception thrown when the item was not found in the persistence store.
/// </summary>
public class IdempotencyItemNotFoundException : Exception
{
/// <summary>
/// Creates a new IdempotencyItemNotFoundException
/// </summary>
public IdempotencyItemNotFoundException()
{
}

/// <inheritdoc />
public IdempotencyItemNotFoundException(string message) : base(message)
{
}

/// <inheritdoc />
public IdempotencyItemNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
}
Loading