Skip to content

Commit

Permalink
Merge pull request #163 from hossambarakat/feature/idempotency
Browse files Browse the repository at this point in the history
Great work!!
  • Loading branch information
hjgraca authored Jun 8, 2023
2 parents 12ddf19 + 33de0e1 commit dba5e90
Show file tree
Hide file tree
Showing 44 changed files with 4,971 additions and 3 deletions.
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 for AWS Lambda (.NET) 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

0 comments on commit dba5e90

Please sign in to comment.