Skip to content

Commit 4f60487

Browse files
committed
Fixed an issue where primitive values in payload for InvokeFunctionCommand were not working.
1 parent 969aa52 commit 4f60487

File tree

8 files changed

+103
-6
lines changed

8 files changed

+103
-6
lines changed

aws-extensions-for-dotnet-cli.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.Tools.Integ.T
6363
EndProject
6464
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestHttpFunction", "testapps\TestHttpFunction\TestHttpFunction.csproj", "{AD31D053-97C5-4262-B187-EC42BFD51A9F}"
6565
EndProject
66-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestNativeAotNet8WebApp", "testapps\TestNativeAotNet8WebApp\TestNativeAotNet8WebApp.csproj", "{69FFA03C-D29F-40E0-9E7F-572D5E10AF77}"
66+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestNativeAotNet8WebApp", "testapps\TestNativeAotNet8WebApp\TestNativeAotNet8WebApp.csproj", "{69FFA03C-D29F-40E0-9E7F-572D5E10AF77}"
67+
EndProject
68+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestIntegerFunction", "testapps\TestIntegerFunction\TestIntegerFunction.csproj", "{D7F1DFA4-066B-469C-B04C-DF032CF152C1}"
6769
EndProject
6870
Global
6971
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -163,6 +165,10 @@ Global
163165
{69FFA03C-D29F-40E0-9E7F-572D5E10AF77}.Debug|Any CPU.Build.0 = Debug|Any CPU
164166
{69FFA03C-D29F-40E0-9E7F-572D5E10AF77}.Release|Any CPU.ActiveCfg = Release|Any CPU
165167
{69FFA03C-D29F-40E0-9E7F-572D5E10AF77}.Release|Any CPU.Build.0 = Release|Any CPU
168+
{D7F1DFA4-066B-469C-B04C-DF032CF152C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
169+
{D7F1DFA4-066B-469C-B04C-DF032CF152C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
170+
{D7F1DFA4-066B-469C-B04C-DF032CF152C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
171+
{D7F1DFA4-066B-469C-B04C-DF032CF152C1}.Release|Any CPU.Build.0 = Release|Any CPU
166172
EndGlobalSection
167173
GlobalSection(SolutionProperties) = preSolution
168174
HideSolutionNode = FALSE
@@ -193,6 +199,7 @@ Global
193199
{7B2AE176-8AB5-4050-8E22-A2A80E88BB92} = {BB0A8314-3127-4159-8B6A-64F97FEF9474}
194200
{AD31D053-97C5-4262-B187-EC42BFD51A9F} = {BB3CF729-8213-4DDD-85AE-A5E7754F3944}
195201
{69FFA03C-D29F-40E0-9E7F-572D5E10AF77} = {BB3CF729-8213-4DDD-85AE-A5E7754F3944}
202+
{D7F1DFA4-066B-469C-B04C-DF032CF152C1} = {BB3CF729-8213-4DDD-85AE-A5E7754F3944}
196203
EndGlobalSection
197204
GlobalSection(ExtensibilityGlobals) = postSolution
198205
SolutionGuid = {DBFC70D6-49A2-40A1-AB08-5D9504AB7112}

src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<Copyright>Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.</Copyright>
1616
<Product>AWS Lambda Tools for .NET CLI</Product>
1717
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
18-
<Version>5.11.0</Version>
18+
<Version>5.11.1</Version>
1919
</PropertyGroup>
2020
<ItemGroup>
2121
<Content Include="Resources\build-lambda-zip.exe">

src/Amazon.Lambda.Tools/Commands/InvokeFunctionCommand.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ protected override void ParseCommandArguments(CommandOptions values)
6262

6363
protected override async Task<bool> PerformActionAsync()
6464
{
65-
6665
var invokeRequest = new InvokeRequest
6766
{
6867
FunctionName = this.GetStringValueOrDefault(this.FunctionName, LambdaDefinedCommandOptions.ARGUMENT_FUNCTION_NAME, true),
@@ -81,9 +80,20 @@ protected override async Task<bool> PerformActionAsync()
8180
invokeRequest.Payload = this.Payload.Trim();
8281
}
8382

84-
if(!invokeRequest.Payload.StartsWith("{"))
83+
// We should still check for empty payload in case it is read from a file.
84+
if (!string.IsNullOrEmpty(invokeRequest.Payload))
8585
{
86-
invokeRequest.Payload = "\"" + invokeRequest.Payload + "\"";
86+
if (invokeRequest.Payload[0] != '\"' && invokeRequest.Payload[0] != '{' && invokeRequest.Payload[0] != '[')
87+
{
88+
double d;
89+
long l;
90+
bool b;
91+
if (!double.TryParse(invokeRequest.Payload, out d) && !long.TryParse(invokeRequest.Payload, out l) &&
92+
!bool.TryParse(invokeRequest.Payload, out b))
93+
{
94+
invokeRequest.Payload = "\"" + invokeRequest.Payload + "\"";
95+
}
96+
}
8797
}
8898
}
8999

test/Amazon.Lambda.Tools.Test/Amazon.Lambda.Tools.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<ItemGroup>
7575
<ProjectReference Include="..\..\src\Amazon.Lambda.Tools\Amazon.Lambda.Tools.csproj" />
7676
<ProjectReference Include="..\..\testapps\TestFunction\TestFunction.csproj" />
77+
<ProjectReference Include="..\..\testapps\TestIntegerFunction\TestIntegerFunction.csproj" />
7778
<ProjectReference Include="..\Amazon.Tools.TestHelpers\Amazon.Tools.TestHelpers.csproj" />
7879
</ItemGroup>
7980
<ItemGroup>

test/Amazon.Lambda.Tools.Test/DeployTest.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,50 @@ public async Task RunDeployCommand()
310310
}
311311
}
312312
}
313-
313+
314+
[Fact]
315+
public async Task RunDeployAndInvokeWithIntegerPayloadCommand()
316+
{
317+
var assembly = this.GetType().GetTypeInfo().Assembly;
318+
var toolLogger = new TestToolLogger(_testOutputHelper);
319+
320+
var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/TestIntegerFunction");
321+
var command = new DeployFunctionCommand(toolLogger, fullPath, new string[0]);
322+
command.FunctionName = "test-function-intpayload-" + DateTime.Now.Ticks;
323+
command.Handler = "TestIntegerFunction::TestIntegerFunction.Function::FunctionHandler";
324+
command.Timeout = 10;
325+
command.MemorySize = 512;
326+
command.Role = await TestHelper.GetTestRoleArnAsync();
327+
command.Configuration = "Release";
328+
command.Runtime = "dotnet6";
329+
command.DisableInteractive = true;
330+
331+
var created = await command.ExecuteAsync();
332+
try
333+
{
334+
Assert.True(created);
335+
336+
await LambdaUtilities.WaitTillFunctionAvailableAsync(new TestToolLogger(_testOutputHelper), command.LambdaClient, command.FunctionName);
337+
338+
toolLogger.ClearBuffer();
339+
340+
var invokeCommand = new InvokeFunctionCommand(toolLogger, fullPath, new string[0]);
341+
invokeCommand.FunctionName = command.FunctionName;
342+
invokeCommand.Payload = "42";
343+
344+
await invokeCommand.ExecuteAsync();
345+
346+
Assert.Contains("\"Hello 42\"", toolLogger.Buffer);
347+
}
348+
finally
349+
{
350+
if (created)
351+
{
352+
await command.LambdaClient.DeleteFunctionAsync(command.FunctionName);
353+
}
354+
}
355+
}
356+
314357
[Fact]
315358
public async Task TestPowerShellLambdaParallelTestCommand()
316359
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace TestIntegerFunction
7+
{
8+
9+
public class Function
10+
{
11+
[Amazon.Lambda.Core.LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
12+
public string FunctionHandler(int input)
13+
{
14+
return "Hello " + input;
15+
}
16+
}
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<AssemblyName>TestIntegerFunction</AssemblyName>
5+
<OutputType>Library</OutputType>
6+
<PackageId>TestIntegerFunction</PackageId>
7+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
8+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
9+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
10+
</PropertyGroup>
11+
<ItemGroup>
12+
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="2.0.0" />
13+
</ItemGroup>
14+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"region": "us-east-2",
3+
"disable-version-check": true,
4+
"function-memory-size": 128
5+
}

0 commit comments

Comments
 (0)