From 0d160f931be9c0a253e7f875c00a7c1af4edde5a Mon Sep 17 00:00:00 2001 From: Sebastien Stormacq Date: Mon, 11 May 2026 20:05:26 +0200 Subject: [PATCH] Revert "Add logGroupName and logStreamName to LambdaContext (#663)" This reverts commit e13b94177ee3c185314879f37040cf7bec019917. --- Sources/AWSLambdaRuntime/Lambda.swift | 7 +-- Sources/AWSLambdaRuntime/LambdaContext.swift | 36 ++--------- .../LambdaContextTests.swift | 62 ------------------- 3 files changed, 7 insertions(+), 98 deletions(-) diff --git a/Sources/AWSLambdaRuntime/Lambda.swift b/Sources/AWSLambdaRuntime/Lambda.swift index 1d768653..10e3522c 100644 --- a/Sources/AWSLambdaRuntime/Lambda.swift +++ b/Sources/AWSLambdaRuntime/Lambda.swift @@ -85,9 +85,6 @@ public enum Lambda { ) async throws where Handler: StreamingLambdaHandler { var handler = handler - let logGroupName = Lambda.env("AWS_LAMBDA_LOG_GROUP_NAME") - let logStreamName = Lambda.env("AWS_LAMBDA_LOG_STREAM_NAME") - do { while !Task.isCancelled { @@ -131,9 +128,7 @@ public enum Lambda { deadline: LambdaClock.Instant( millisecondsSinceEpoch: invocation.metadata.deadlineInMillisSinceEpoch ), - logger: requestLogger, - logGroupName: logGroupName, - logStreamName: logStreamName + logger: requestLogger ) ) requestLogger.trace("Handler finished processing invocation") diff --git a/Sources/AWSLambdaRuntime/LambdaContext.swift b/Sources/AWSLambdaRuntime/LambdaContext.swift index a62959ee..d14e16c6 100644 --- a/Sources/AWSLambdaRuntime/LambdaContext.swift +++ b/Sources/AWSLambdaRuntime/LambdaContext.swift @@ -99,8 +99,6 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable { let cognitoIdentity: String? let clientContext: ClientContext? let logger: Logger - let logGroupName: String? - let logStreamName: String? init( requestID: String, @@ -110,9 +108,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable { deadline: LambdaClock.Instant, cognitoIdentity: String?, clientContext: ClientContext?, - logger: Logger, - logGroupName: String?, - logStreamName: String? + logger: Logger ) { self.requestID = requestID self.traceID = traceID @@ -122,8 +118,6 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable { self.cognitoIdentity = cognitoIdentity self.clientContext = clientContext self.logger = logger - self.logGroupName = logGroupName - self.logStreamName = logStreamName } } @@ -175,7 +169,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable { *, deprecated, message: - "This method will be removed in a future major version update. Use init(requestID:traceID:tenantID:invokedFunctionARN:deadline:cognitoIdentity:clientContext:logger:logGroupName:logStreamName) instead." + "This method will be removed in a future major version update. Use init(requestID:traceID:tenantID:invokedFunctionARN:deadline:cognitoIdentity:clientContext:logger) instead." ) public init( requestID: String, @@ -205,9 +199,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable { deadline: LambdaClock.Instant, cognitoIdentity: String? = nil, clientContext: ClientContext? = nil, - logger: Logger, - logGroupName: String? = nil, - logStreamName: String? = nil + logger: Logger ) { self.storage = _Storage( requestID: requestID, @@ -217,22 +209,10 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable { deadline: deadline, cognitoIdentity: cognitoIdentity, clientContext: clientContext, - logger: logger, - logGroupName: logGroupName, - logStreamName: logStreamName + logger: logger ) } - /// The name of the Amazon CloudWatch Logs group for the function. - public var logGroupName: String? { - self.storage.logGroupName - } - - /// The name of the Amazon CloudWatch Logs stream for the current invocation of the function. - public var logStreamName: String? { - self.storage.logStreamName - } - public func getRemainingTime() -> Duration { let deadline = self.deadline return LambdaClock().now.duration(to: deadline) @@ -250,9 +230,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable { tenantID: String?, invokedFunctionARN: String, timeout: Duration, - logger: Logger, - logGroupName: String? = nil, - logStreamName: String? = nil + logger: Logger ) -> LambdaContext { LambdaContext( requestID: requestID, @@ -260,9 +238,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable { tenantID: tenantID, invokedFunctionARN: invokedFunctionARN, deadline: LambdaClock().now.advanced(by: timeout), - logger: logger, - logGroupName: logGroupName, - logStreamName: logStreamName + logger: logger ) } } diff --git a/Tests/AWSLambdaRuntimeTests/LambdaContextTests.swift b/Tests/AWSLambdaRuntimeTests/LambdaContextTests.swift index 9c72b667..bac85e5e 100644 --- a/Tests/AWSLambdaRuntimeTests/LambdaContextTests.swift +++ b/Tests/AWSLambdaRuntimeTests/LambdaContextTests.swift @@ -136,66 +136,4 @@ struct LambdaContextTests { #expect(remainingTime <= Duration.seconds(31), "Remaining time should be approximately 30 seconds") #expect(remainingTime >= Duration.seconds(-29), "Remaining time should be approximately -30 seconds") } - - @Test("logGroupName returns the value passed at initialization") - @available(LambdaSwift 2.0, *) - func logGroupNameReturnsInitializedValue() { - let context = LambdaContext.__forTestsOnly( - requestID: "test-request", - traceID: "test-trace", - tenantID: nil, - invokedFunctionARN: "test-arn", - timeout: .seconds(30), - logger: Logger(label: "test"), - logGroupName: "/aws/lambda/my-function" - ) - - #expect(context.logGroupName == "/aws/lambda/my-function") - } - - @Test("logStreamName returns the value passed at initialization") - @available(LambdaSwift 2.0, *) - func logStreamNameReturnsInitializedValue() { - let context = LambdaContext.__forTestsOnly( - requestID: "test-request", - traceID: "test-trace", - tenantID: nil, - invokedFunctionARN: "test-arn", - timeout: .seconds(30), - logger: Logger(label: "test"), - logStreamName: "2024/01/01/[$LATEST]abcdef1234567890" - ) - - #expect(context.logStreamName == "2024/01/01/[$LATEST]abcdef1234567890") - } - - @Test("logGroupName defaults to nil") - @available(LambdaSwift 2.0, *) - func logGroupNameDefaultsToNil() { - let context = LambdaContext.__forTestsOnly( - requestID: "test-request", - traceID: "test-trace", - tenantID: nil, - invokedFunctionARN: "test-arn", - timeout: .seconds(30), - logger: Logger(label: "test") - ) - - #expect(context.logGroupName == nil) - } - - @Test("logStreamName defaults to nil") - @available(LambdaSwift 2.0, *) - func logStreamNameDefaultsToNil() { - let context = LambdaContext.__forTestsOnly( - requestID: "test-request", - traceID: "test-trace", - tenantID: nil, - invokedFunctionARN: "test-arn", - timeout: .seconds(30), - logger: Logger(label: "test") - ) - - #expect(context.logStreamName == nil) - } }