Skip to content

chore: idempotency e2e tests #738

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 16 additions & 12 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PROCESS
#
# 1. Deploy the core and AOT stacks using the infra deployment workflow.
# 1. Deploy the E2E stacks using the infra deployment workflow for non-aot and aot.
# 2. Run the E2E tests after the infrastructure is deployed.
# 3. Destroy the CDK stacks after the tests are completed.

Expand Down Expand Up @@ -50,10 +50,10 @@ jobs:
- name: Install AWS Lambda .NET CLI Tools
run: dotnet tool install -g Amazon.Lambda.Tools

- name: Deploy Core Stack
- name: Deploy Stack
run: |
cd libraries/tests/e2e/infra
cdk deploy --require-approval never
cdk deploy --all --require-approval never

deploy-aot-stack:
strategy:
Expand Down Expand Up @@ -90,11 +90,15 @@ jobs:
- name: Deploy AOT Stack
run: |
cd libraries/tests/e2e/infra-aot
cdk deploy -c architecture=${{ matrix.arch }} --require-approval never
cdk deploy --all -c architecture=${{ matrix.arch }} --require-approval never

run-tests:
strategy:
matrix:
utility: [core, idempotency]
runs-on: ubuntu-latest
needs: [deploy-stack,deploy-aot-stack]

steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Expand All @@ -111,14 +115,14 @@ jobs:
with:
dotnet-version: '8.x'

- name: Run Core Tests
- name: Run Tests
run: |
cd libraries/tests/e2e/functions/core
cd libraries/tests/e2e/functions/${{ matrix.utility }}
dotnet test --filter Category!=AOT

- name: Run Core AOT Tests
- name: Run AOT Tests
run: |
cd libraries/tests/e2e/functions/core
cd libraries/tests/e2e/functions/${{ matrix.utility }}
dotnet test --filter Category=AOT

destroy-stack:
Expand All @@ -142,10 +146,10 @@ jobs:
- name: Install AWS Lambda .NET CLI Tools
run: dotnet tool install -g Amazon.Lambda.Tools

- name: Destroy Core Stack
- name: Destroy Stack
run: |
cd libraries/tests/e2e/infra
cdk destroy --force
cdk destroy --all --force

destroy-aot-stack:
strategy:
Expand Down Expand Up @@ -176,8 +180,8 @@ jobs:
- name: Install AWS Lambda .NET CLI Tools
run: dotnet tool install -g Amazon.Lambda.Tools

- name: Destroy arm64 AOT Core Stack
- name: Destroy arm64 AOT Stack
run: |
cd libraries/tests/e2e/infra-aot
cdk destroy -c architecture=${{ matrix.arch }} --force
cdk destroy --all -c architecture=${{ matrix.arch }} --force

69 changes: 66 additions & 3 deletions libraries/AWS.Lambda.Powertools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infra", "Infra", "{93DEAC72-245F-4FC9-A7B5-DAE7EF7E1AB7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Functions", "Functions", "{CDAE55EB-9438-4F54-B7ED-931D64324D5F}"
ProjectSection(SolutionItems) = preProject
tests\e2e\functions\payload.json = tests\e2e\functions\payload.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infra", "tests\e2e\infra\Infra.csproj", "{AA532674-A61C-41E6-8F9A-ED53D79AF1EC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{AAFA39E9-66A3-4B9A-AFE9-EAF74A85A7F0}"
ProjectSection(SolutionItems) = preProject
tests\e2e\functions\core\payload.json = tests\e2e\functions\core\payload.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils", "tests\e2e\functions\TestUtils\TestUtils.csproj", "{3C6162D7-0162-4BC2-BBF5-0554539A81CD}"
EndProject
Expand Down Expand Up @@ -83,6 +83,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOT-Function", "tests\e2e\f
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InfraAot", "tests\e2e\infra-aot\InfraAot.csproj", "{24AC34AD-AEC9-4CFB-BB01-C3C81938AB95}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InfraShared", "tests\e2e\InfraShared\InfraShared.csproj", "{D303B458-9D84-4DDF-8781-2C0211672329}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Idempotency", "Idempotency", "{FB2C7DA3-6FCE-429D-86F9-5775D0231EC6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Function", "tests\e2e\functions\idempotency\Function\src\Function\Function.csproj", "{9AF99F6D-E8E7-443F-A965-D55B8E388836}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Function.Tests", "tests\e2e\functions\idempotency\Function\test\Function.Tests\Function.Tests.csproj", "{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOT-Function", "tests\e2e\functions\idempotency\AOT-Function\src\AOT-Function\AOT-Function.csproj", "{56DFC68A-3994-43CD-A17C-323495F1709C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -432,6 +442,54 @@ Global
{24AC34AD-AEC9-4CFB-BB01-C3C81938AB95}.Release|x64.Build.0 = Release|Any CPU
{24AC34AD-AEC9-4CFB-BB01-C3C81938AB95}.Release|x86.ActiveCfg = Release|Any CPU
{24AC34AD-AEC9-4CFB-BB01-C3C81938AB95}.Release|x86.Build.0 = Release|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|x64.ActiveCfg = Debug|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|x64.Build.0 = Debug|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|x86.ActiveCfg = Debug|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Debug|x86.Build.0 = Debug|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|Any CPU.Build.0 = Release|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|x64.ActiveCfg = Release|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|x64.Build.0 = Release|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|x86.ActiveCfg = Release|Any CPU
{D303B458-9D84-4DDF-8781-2C0211672329}.Release|x86.Build.0 = Release|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|x64.ActiveCfg = Debug|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|x64.Build.0 = Debug|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|x86.ActiveCfg = Debug|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Debug|x86.Build.0 = Debug|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|Any CPU.Build.0 = Release|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|x64.ActiveCfg = Release|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|x64.Build.0 = Release|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|x86.ActiveCfg = Release|Any CPU
{9AF99F6D-E8E7-443F-A965-D55B8E388836}.Release|x86.Build.0 = Release|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|x64.ActiveCfg = Debug|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|x64.Build.0 = Debug|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|x86.ActiveCfg = Debug|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Debug|x86.Build.0 = Debug|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|Any CPU.Build.0 = Release|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|x64.ActiveCfg = Release|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|x64.Build.0 = Release|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|x86.ActiveCfg = Release|Any CPU
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC}.Release|x86.Build.0 = Release|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Debug|x64.ActiveCfg = Debug|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Debug|x64.Build.0 = Debug|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Debug|x86.ActiveCfg = Debug|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Debug|x86.Build.0 = Debug|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Release|Any CPU.Build.0 = Release|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Release|x64.ActiveCfg = Release|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Release|x64.Build.0 = Release|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Release|x86.ActiveCfg = Release|Any CPU
{56DFC68A-3994-43CD-A17C-323495F1709C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection

GlobalSection(NestedProjects) = preSolution
Expand Down Expand Up @@ -470,5 +528,10 @@ Global
{8DDAFE37-ED59-4710-9415-8EBA44CC6437} = {3C9FA701-31FF-4747-B324-E0D252EAFD63}
{8DDED681-AE8D-45EB-A22E-2FFB88620F9B} = {3C9FA701-31FF-4747-B324-E0D252EAFD63}
{24AC34AD-AEC9-4CFB-BB01-C3C81938AB95} = {93DEAC72-245F-4FC9-A7B5-DAE7EF7E1AB7}
{D303B458-9D84-4DDF-8781-2C0211672329} = {93DEAC72-245F-4FC9-A7B5-DAE7EF7E1AB7}
{FB2C7DA3-6FCE-429D-86F9-5775D0231EC6} = {CDAE55EB-9438-4F54-B7ED-931D64324D5F}
{9AF99F6D-E8E7-443F-A965-D55B8E388836} = {FB2C7DA3-6FCE-429D-86F9-5775D0231EC6}
{FBCE2C8A-2F64-4B62-8CF1-D4A14C19A5CC} = {FB2C7DA3-6FCE-429D-86F9-5775D0231EC6}
{56DFC68A-3994-43CD-A17C-323495F1709C} = {FB2C7DA3-6FCE-429D-86F9-5775D0231EC6}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
using System.Collections.Generic;
using Amazon.CDK;
using Amazon.CDK.AWS.Lambda;
using Constructs;
using TestUtils;

namespace Infra;
namespace InfraShared;

public class FunctionConstruct : Construct
{
public Function Function { get; set; }

public FunctionConstruct(Construct scope, string id, FunctionConstructProps props) : base(scope, id)
{
var framework = props.Runtime == Runtime.DOTNET_6 ? "net6.0" : "net8.0";
var distPath = $"{props.DistPath}/deploy_{props.Architecture.Name}_{props.Runtime.Name}.zip";
_ = new Function(this, id, new FunctionProps
var command = props.IsAot
? $"dotnet-lambda package -pl {props.SourcePath} -cmd ../../../ -o {distPath} -f net8.0 -farch {props.Architecture.Name} -cifb public.ecr.aws/sam/build-dotnet8"
: $"dotnet-lambda package -pl {props.SourcePath} -o {distPath} -f {framework} -farch {props.Architecture.Name}";

Console.WriteLine(command);

Function = new Function(this, id, new FunctionProps
{
Runtime = props.Runtime,
Architecture = props.Architecture,
FunctionName = props.Name,
Handler = props.Handler,
Tracing = Tracing.ACTIVE,
Timeout = Duration.Seconds(10),
Environment = props.Environment,
Code = Code.FromCustomCommand(distPath,
[
$"dotnet-lambda package -pl {props.SourcePath} -o {distPath} -f {framework} -farch {props.Architecture.Name}"
command
],
new CustomCommandOptions
{
CommandOptions = new Dictionary<string, object> {{"shell", true }}
CommandOptions = new Dictionary<string, object> { { "shell", true } }
})
});
}
Expand Down
26 changes: 26 additions & 0 deletions libraries/tests/e2e/InfraShared/FunctionConstructProps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Amazon.CDK;
using Amazon.CDK.AWS.Lambda;

namespace InfraShared;

public class FunctionConstructProps : PowertoolsDefaultStackProps
{
public required Architecture Architecture { get; set; }
public required Runtime Runtime { get; set; }
public required string Name { get; set; }
public required string Handler { get; set; }
public required string SourcePath { get; set; }
public required string DistPath { get; set; }
}

public class PowertoolsDefaultStackProps : StackProps
{
public bool IsAot { get; set; } = false;
public string? ArchitectureString { get; set; }
public Dictionary<string,string>? Environment { get; set; }
}

public class IdempotencyStackProps : PowertoolsDefaultStackProps
{
public required string TableName { get; set; }
}
81 changes: 81 additions & 0 deletions libraries/tests/e2e/InfraShared/IdempotencyStack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Amazon.CDK;
using Amazon.CDK.AWS.DynamoDB;
using Amazon.CDK.AWS.Lambda;
using Constructs;
using Attribute = Amazon.CDK.AWS.DynamoDB.Attribute;

namespace InfraShared;

public class IdempotencyStack : Stack
{
public Table Table { get; set; }

public IdempotencyStack(Construct scope, string id, IdempotencyStackProps props) : base(scope, id, props)
{
Table = new Table(this, "Idempotency", new TableProps
{
PartitionKey = new Attribute
{
Name = "id",
Type = AttributeType.STRING
},
TableName = props.TableName,
BillingMode = BillingMode.PAY_PER_REQUEST,
TimeToLiveAttribute = "expiration",
RemovalPolicy = RemovalPolicy.DESTROY
});

var utility = "idempotency";

if (props.IsAot)
{
var baseAotPath = $"../functions/{utility}/AOT-Function/src/AOT-Function";
var distAotPath = $"../functions/{utility}/AOT-Function/dist";
var path = new Path(baseAotPath, distAotPath);

var architecture = props.ArchitectureString == "arm64" ? Architecture.ARM_64 : Architecture.X86_64;
var arch = architecture == Architecture.X86_64 ? "X64" : "ARM";
CreateFunctionConstruct(this, $"{utility}_{arch}_aot_net8", Runtime.DOTNET_8, architecture,
$"E2ETestLambda_{arch}_AOT_NET8_{utility}", path, props);
}
else
{
var basePath = $"../functions/{utility}/Function/src/Function";
var distPath = $"../functions/{utility}/Function/dist";
var path = new Path(basePath, distPath);

CreateFunctionConstruct(this, $"{utility}_X64_net8", Runtime.DOTNET_8, Architecture.X86_64,
$"E2ETestLambda_X64_NET8_{utility}", path, props);
CreateFunctionConstruct(this, $"{utility}_arm_net8", Runtime.DOTNET_8, Architecture.ARM_64,
$"E2ETestLambda_ARM_NET8_{utility}", path, props);
CreateFunctionConstruct(this, $"{utility}_X64_net6", Runtime.DOTNET_6, Architecture.X86_64,
$"E2ETestLambda_X64_NET6_{utility}", path, props);
CreateFunctionConstruct(this, $"{utility}_arm_net6", Runtime.DOTNET_6, Architecture.ARM_64,
$"E2ETestLambda_ARM_NET6_{utility}", path, props);
}
}

private void CreateFunctionConstruct(Construct scope, string id, Runtime runtime, Architecture architecture,
string name,Path path, PowertoolsDefaultStackProps props)
{
var lambdaFunction = new FunctionConstruct(scope, id, new FunctionConstructProps
{
Runtime = runtime,
Architecture = architecture,
Name = name,
Handler = props.IsAot ? "AOT-Function" : "Function::Function.Function::FunctionHandler",
SourcePath = path.SourcePath,
DistPath = path.DistPath,
Environment = new Dictionary<string, string>
{
{ "IDEMPOTENCY_TABLE_NAME", Table.TableName }
},
IsAot = props.IsAot
});

// Grant the Lambda function permissions to perform all actions on the DynamoDB table
Table.GrantReadWriteData(lambdaFunction.Function);
}
}

public record Path(string SourcePath, string DistPath);
19 changes: 19 additions & 0 deletions libraries/tests/e2e/InfraShared/InfraShared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>InfraShared</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<!-- CDK Construct Library dependencies -->
<PackageReference Include="Amazon.CDK.Lib" Version="2.174.0" />
<PackageReference Include="Constructs" Version="10.4.2" />

<!-- jsii Roslyn analyzers (un-comment to obtain compile-time checks for missing required props
<PackageReference Include="Amazon.Jsii.Analyzers" Version="*" PrivateAssets="all" />
-->
</ItemGroup>
</Project>
13 changes: 0 additions & 13 deletions libraries/tests/e2e/functions/TestUtils/FunctionConstructProps.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal async Task TestFunction(string functionName)
{
FunctionName = functionName,
InvocationType = InvocationType.RequestResponse,
Payload = await File.ReadAllTextAsync("../../../../../../../payload.json"),
Payload = await File.ReadAllTextAsync("../../../../../../../../payload.json"),
LogType = LogType.Tail
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public FunctionTests(ITestOutputHelper testOutputHelper)
[Trait("Category", "AOT")]
[Theory]
[InlineData("E2ETestLambda_X64_AOT_NET8_metrics")]
// [InlineData("E2ETestLambda_ARM_AOT_NET8_metrics")]
[InlineData("E2ETestLambda_ARM_AOT_NET8_metrics")]
public async Task AotFunctionTest(string functionName)
{
await TestFunction(functionName);
Expand All @@ -45,7 +45,7 @@ internal async Task TestFunction(string functionName)
{
FunctionName = functionName,
InvocationType = InvocationType.RequestResponse,
Payload = await File.ReadAllTextAsync("../../../../../../../payload.json"),
Payload = await File.ReadAllTextAsync("../../../../../../../../payload.json"),
LogType = LogType.Tail
};

Expand Down
Loading
Loading