@@ -49,40 +49,94 @@ extension Lambda {
4949extension Lambda {
5050 /// Lambda runtime context.
5151 /// The Lambda runtime generates and passes the `Context` to the Lambda handler as an argument.
52- public final class Context : CustomDebugStringConvertible {
52+ public struct Context : CustomDebugStringConvertible {
53+ final class _Storage {
54+ var requestID : String
55+ var traceID : String
56+ var invokedFunctionARN : String
57+ var deadline : DispatchWallTime
58+ var cognitoIdentity : String ?
59+ var clientContext : String ?
60+ var logger : Logger
61+ var eventLoop : EventLoop
62+ var allocator : ByteBufferAllocator
63+
64+ init (
65+ requestID: String ,
66+ traceID: String ,
67+ invokedFunctionARN: String ,
68+ deadline: DispatchWallTime ,
69+ cognitoIdentity: String ? ,
70+ clientContext: String ? ,
71+ logger: Logger ,
72+ eventLoop: EventLoop ,
73+ allocator: ByteBufferAllocator
74+ ) {
75+ self . requestID = requestID
76+ self . traceID = traceID
77+ self . invokedFunctionARN = invokedFunctionARN
78+ self . deadline = deadline
79+ self . cognitoIdentity = cognitoIdentity
80+ self . clientContext = clientContext
81+ self . logger = logger
82+ self . eventLoop = eventLoop
83+ self . allocator = allocator
84+ }
85+ }
86+
87+ private var storage : _Storage
88+
5389 /// The request ID, which identifies the request that triggered the function invocation.
54- public let requestID : String
90+ public var requestID : String {
91+ self . storage. requestID
92+ }
5593
5694 /// The AWS X-Ray tracing header.
57- public let traceID : String
95+ public var traceID : String {
96+ self . storage. traceID
97+ }
5898
5999 /// The ARN of the Lambda function, version, or alias that's specified in the invocation.
60- public let invokedFunctionARN : String
100+ public var invokedFunctionARN : String {
101+ self . storage. invokedFunctionARN
102+ }
61103
62104 /// The timestamp that the function times out
63- public let deadline : DispatchWallTime
105+ public var deadline : DispatchWallTime {
106+ self . storage. deadline
107+ }
64108
65109 /// For invocations from the AWS Mobile SDK, data about the Amazon Cognito identity provider.
66- public let cognitoIdentity : String ?
110+ public var cognitoIdentity : String ? {
111+ self . storage. cognitoIdentity
112+ }
67113
68114 /// For invocations from the AWS Mobile SDK, data about the client application and device.
69- public let clientContext : String ?
115+ public var clientContext : String ? {
116+ self . storage. clientContext
117+ }
70118
71119 /// `Logger` to log with
72120 ///
73121 /// - note: The `LogLevel` can be configured using the `LOG_LEVEL` environment variable.
74- public let logger : Logger
122+ public var logger : Logger {
123+ self . storage. logger
124+ }
75125
76126 /// The `EventLoop` the Lambda is executed on. Use this to schedule work with.
77127 /// This is useful when implementing the `EventLoopLambdaHandler` protocol.
78128 ///
79129 /// - note: The `EventLoop` is shared with the Lambda runtime engine and should be handled with extra care.
80130 /// Most importantly the `EventLoop` must never be blocked.
81- public let eventLoop : EventLoop
131+ public var eventLoop : EventLoop {
132+ self . storage. eventLoop
133+ }
82134
83135 /// `ByteBufferAllocator` to allocate `ByteBuffer`
84136 /// This is useful when implementing `EventLoopLambdaHandler`
85- public let allocator : ByteBufferAllocator
137+ public var allocator : ByteBufferAllocator {
138+ self . storage. allocator
139+ }
86140
87141 internal init ( requestID: String ,
88142 traceID: String ,
@@ -92,22 +146,16 @@ extension Lambda {
92146 clientContext: String ? = nil ,
93147 logger: Logger ,
94148 eventLoop: EventLoop ,
95- allocator: ByteBufferAllocator )
96- {
97- self . requestID = requestID
98- self . traceID = traceID
99- self . invokedFunctionARN = invokedFunctionARN
100- self . cognitoIdentity = cognitoIdentity
101- self . clientContext = clientContext
102- self . deadline = deadline
103- // utility
104- self . eventLoop = eventLoop
105- self . allocator = allocator
106- // mutate logger with context
107- var logger = logger
108- logger [ metadataKey: " awsRequestID " ] = . string( requestID)
109- logger [ metadataKey: " awsTraceID " ] = . string( traceID)
110- self . logger = logger
149+ allocator: ByteBufferAllocator ) {
150+ self . storage = _Storage ( requestID: requestID,
151+ traceID: traceID,
152+ invokedFunctionARN: invokedFunctionARN,
153+ deadline: deadline,
154+ cognitoIdentity: cognitoIdentity,
155+ clientContext: clientContext,
156+ logger: logger,
157+ eventLoop: eventLoop,
158+ allocator: allocator)
111159 }
112160
113161 public func getRemainingTime( ) -> TimeAmount {
0 commit comments