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

Implement support for function-timeout configuration #1852

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class LambdaConfigFile
public string FunctionHandler { get; set; }
[JsonPropertyName("function-name")]
public string FunctionName { get; set; }
[JsonPropertyName("function-timeout")]
public int? FunctionTimeOut { get; set; }

[JsonPropertyName("image-command")]
public string ImageCommand { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ public static LambdaConfigInfo LoadFromFile(LambdaConfigFile configFile)
info.Name = functionHandler;
}

if(configFile.EnvironmentVariables != null)
info.Timeout = configFile.FunctionTimeOut.HasValue
? TimeSpan.FromSeconds(configFile.FunctionTimeOut.Value)
: TimeSpan.FromMinutes(15);

if (configFile.EnvironmentVariables != null)
{
ParseKeyValueOption(configFile.EnvironmentVariables, info.EnvironmentVariables);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public async Task<ExecutionResponse> ExecuteAsync(ExecutionRequest request)
Logger = logger,
AwsRequestId = Guid.NewGuid().ToString(),
FunctionName = request.Function.FunctionInfo.Name,
InvokedFunctionArn = string.Format("arn:aws:lambda:{0}::function:{1}", request.AWSRegion, request.Function.FunctionInfo.Name)
InvokedFunctionArn = string.Format("arn:aws:lambda:{0}::function:{1}", request.AWSRegion, request.Function.FunctionInfo.Name),
RemainingTime = request.Function.FunctionInfo.Timeout
};

object instance = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace Amazon.Lambda.TestTool.Runtime
{
Expand All @@ -14,6 +15,11 @@ public class LambdaFunctionInfo
/// </summary>
public string Handler { get; set; }

/// <summary>
/// The amount of time the lambda function has to run before it times out.
/// </summary>
public TimeSpan Timeout { get; set; }

public IDictionary<string, string> EnvironmentVariables { get; } = new Dictionary<string, string>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ public void SetRegion()
}
}

[Fact]
public void SetTimeOut()
{
var jsonFile = WriteTempConfigFile("{\"function-timeout\" : 30, \"function-handler\" : \"Assembly::Type::Method\"}");
try
{
var configInfo = LambdaDefaultsConfigFileParser.LoadFromFile(jsonFile);
Assert.Single(configInfo.FunctionInfos);
Assert.Equal(TimeSpan.FromSeconds(30), configInfo.FunctionInfos[0].Timeout);
}
finally
{
File.Delete(jsonFile);
}
}

[Fact]
public void LoadServerlessTemplateConfig()
{
Expand Down