Skip to content

Commit 0903737

Browse files
committed
Remove distant future and use hardcoded max lambda execution time in HTTP local server
1 parent e7eed85 commit 0903737

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Sources/AWSLambdaRuntime/Lambda+LocalServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ internal struct LambdaHTTPServer {
650650
"arn:aws:lambda:us-east-1:\(Int16.random(in: Int16.min ... Int16.max)):function:custom-runtime"
651651
),
652652
(AmazonHeaders.traceID, "Root=\(AmazonHeaders.generateXRayTraceID());Sampled=1"),
653-
(AmazonHeaders.deadline, "\(Duration.distantFuture.milliseconds())"),
653+
(AmazonHeaders.deadline, "\(Duration.maxLambdaExecutionTime.milliseconds())"),
654654
])
655655

656656
return LocalServerResponse(

Sources/AWSLambdaRuntime/Utils.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,20 @@ extension Duration {
5252
return .milliseconds(Int64(ts.tv_sec) * 1000 + Int64(ts.tv_nsec) / 1_000_000)
5353
}
5454

55-
/// Returns a Duration between Unix epoch and the distant future
55+
/// Hardcoded maximum execution time for a Lambda function.
5656
@usableFromInline
57-
static var distantFuture: Duration {
58-
// Use a very large value to represent the distant future
59-
millisSinceEpoch + Duration.seconds(.greatestFiniteMagnitude)
57+
static var maxLambdaExecutionTime: Duration {
58+
// 15 minutes in milliseconds
59+
// see https://docs.aws.amazon.com/lambda/latest/dg/configuration-timeout.html
60+
.milliseconds(15 * 60 * 1000)
61+
}
62+
63+
/// Returns the maximum deadline for a Lambda function execution.
64+
/// This is the current time plus the maximum execution time.
65+
/// This function is onwly used by the local server for testing purposes.
66+
@usableFromInline
67+
static var maxLambdaDeadline: Duration {
68+
millisSinceEpoch + maxLambdaExecutionTime
6069
}
6170

6271
/// Returns the Duration in milliseconds

0 commit comments

Comments
 (0)