Skip to content

Commit 0c8b3c1

Browse files
authored
Add DynamoDB Streams event source emulator (#2356)
1 parent 8516153 commit 0c8b3c1

11 files changed

Lines changed: 1143 additions & 2 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.Lambda.TestTool",
5+
"Type": "Minor",
6+
"ChangelogMessages": [
7+
"Add support emulating Lambda DynamoDB Stream event source"
8+
]
9+
}
10+
]
11+
}

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Amazon.Lambda.TestTool.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.3.22" />
2727
<PackageReference Include="AWSSDK.Lambda" Version="4.0.13.1" />
2828
<PackageReference Include="AWSSDK.SQS" Version="4.0.2.14" />
29+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="4.0.15.2" />
30+
<PackageReference Include="AWSSDK.DynamoDBStreams" Version="4.0.4.17" />
31+
<PackageReference Include="Amazon.Lambda.DynamoDBEvents" Version="3.1.2" />
2932
<PackageReference Include="AWSSDK.SSO" Version="4.0.2.13" />
3033
<PackageReference Include="AWSSDK.SSOOIDC" Version="4.0.3.14" />
3134
<PackageReference Include="Spectre.Console" Version="0.49.1" />

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/RunCommand.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Amazon.Lambda.TestTool.Models;
99
using Amazon.Lambda.TestTool.Processes;
1010
using Amazon.Lambda.TestTool.Processes.SQSEventSource;
11+
using Amazon.Lambda.TestTool.Processes.DynamoDBStreamsEventSource;
1112
using Amazon.Lambda.TestTool.Services;
1213
using Amazon.Lambda.TestTool.Services.IO;
1314
using Spectre.Console.Cli;
@@ -39,10 +40,10 @@ public override async Task<int> ExecuteAsync(CommandContext context, RunCommandS
3940
{
4041
EvaluateEnvironmentVariables(settings);
4142

42-
if (!settings.LambdaEmulatorPort.HasValue && !settings.ApiGatewayEmulatorPort.HasValue && !settings.ApiGatewayEmulatorHttpsPort.HasValue && string.IsNullOrEmpty(settings.SQSEventSourceConfig))
43+
if (!settings.LambdaEmulatorPort.HasValue && !settings.ApiGatewayEmulatorPort.HasValue && !settings.ApiGatewayEmulatorHttpsPort.HasValue && string.IsNullOrEmpty(settings.SQSEventSourceConfig) && string.IsNullOrEmpty(settings.DynamoDBStreamsEventSourceConfig))
4344
{
4445
throw new ArgumentException("At least one of the following parameters must be set: " +
45-
"--lambda-emulator-port, --api-gateway-emulator-port, --api-gateway-emulator-https-port or --sqs-eventsource-config");
46+
"--lambda-emulator-port, --api-gateway-emulator-port, --api-gateway-emulator-https-port, --sqs-eventsource-config or --dynamodbstreams-eventsource-config");
4647
}
4748

4849
var tasks = new List<Task>();
@@ -87,6 +88,12 @@ public override async Task<int> ExecuteAsync(CommandContext context, RunCommandS
8788
{
8889
var sqsEventSourceProcess = SQSEventSourceProcess.Startup(settings, cancellationTokenSource.Token);
8990
tasks.Add(sqsEventSourceProcess.RunningTask);
91+
}
92+
93+
if (!string.IsNullOrEmpty(settings.DynamoDBStreamsEventSourceConfig))
94+
{
95+
var dynamoDBStreamsProcess = DynamoDBStreamsEventSourceProcess.Startup(settings, cancellationTokenSource.Token);
96+
tasks.Add(dynamoDBStreamsProcess.RunningTask);
9097
}
9198

9299
await Task.Run(() => Task.WaitAny(tasks.ToArray(), cancellationTokenSource.Token));
@@ -184,6 +191,16 @@ private void EvaluateEnvironmentVariables(RunCommandSettings settings)
184191
throw new InvalidOperationException($"Environment variable {envVariable} for the SQS event source config was empty");
185192
}
186193
settings.SQSEventSourceConfig = environmentVariables[envVariable]?.ToString();
194+
}
195+
196+
if (settings.DynamoDBStreamsEventSourceConfig != null && settings.DynamoDBStreamsEventSourceConfig.StartsWith(Constants.ArgumentEnvironmentVariablePrefix, StringComparison.CurrentCultureIgnoreCase))
197+
{
198+
var envVariable = settings.DynamoDBStreamsEventSourceConfig.Substring(Constants.ArgumentEnvironmentVariablePrefix.Length);
199+
if (!environmentVariables.Contains(envVariable))
200+
{
201+
throw new InvalidOperationException($"Environment variable {envVariable} for the DynamoDB Streams event source config was empty");
202+
}
203+
settings.DynamoDBStreamsEventSourceConfig = environmentVariables[envVariable]?.ToString();
187204
}
188205
}
189206
}

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/RunCommandSettings.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ public sealed class RunCommandSettings : CommandSettings
8282
[Description("The configuration for the SQS event source. The format of the config is a comma delimited key pairs. For example \"QueueUrl=<queue-url>,FunctionName=<function-name>,VisibilityTimeout=100\". Possible keys are: BatchSize, DisableMessageDelete, FunctionName, LambdaRuntimeApi, Profile, QueueUrl, Region, VisibilityTimeout")]
8383
public string? SQSEventSourceConfig { get; set; }
8484

85+
86+
/// <summary>
87+
/// The configuration for the DynamoDB Streams event source. The config can be provided as comma delimited key pairs, a JSON object, a JSON array, or a file path to a JSON configuration file. For example "TableName=my-table,FunctionName=function-name,BatchSize=100".
88+
/// Possible keys are: BatchSize, FunctionName, LambdaRuntimeApi, PollingIntervalMs, Profile, Region, TableName
89+
/// </summary>
90+
[CommandOption("--dynamodbstreams-eventsource-config <CONFIG>")]
91+
[Description("The configuration for the DynamoDB Streams event source. The config can be provided as comma delimited key pairs, a JSON object, a JSON array, or a file path to a JSON configuration file. For example \"TableName=<table-name>,FunctionName=<function-name>,BatchSize=100\". Possible keys are: BatchSize, FunctionName, LambdaRuntimeApi, PollingIntervalMs, Profile, Region, TableName")]
92+
public string? DynamoDBStreamsEventSourceConfig { get; set; }
8593
/// <summary>
8694
/// The absolute path used to save global settings and saved requests. You will need to specify a path in order to enable saving global settings and requests.
8795
/// </summary>

0 commit comments

Comments
 (0)