@@ -49,40 +49,94 @@ extension Lambda {
49
49
extension Lambda {
50
50
/// Lambda runtime context.
51
51
/// 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
+
53
89
/// 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
+ }
55
93
56
94
/// The AWS X-Ray tracing header.
57
- public let traceID : String
95
+ public var traceID : String {
96
+ self . storage. traceID
97
+ }
58
98
59
99
/// 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
+ }
61
103
62
104
/// The timestamp that the function times out
63
- public let deadline : DispatchWallTime
105
+ public var deadline : DispatchWallTime {
106
+ self . storage. deadline
107
+ }
64
108
65
109
/// 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
+ }
67
113
68
114
/// 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
+ }
70
118
71
119
/// `Logger` to log with
72
120
///
73
121
/// - 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
+ }
75
125
76
126
/// The `EventLoop` the Lambda is executed on. Use this to schedule work with.
77
127
/// This is useful when implementing the `EventLoopLambdaHandler` protocol.
78
128
///
79
129
/// - note: The `EventLoop` is shared with the Lambda runtime engine and should be handled with extra care.
80
130
/// Most importantly the `EventLoop` must never be blocked.
81
- public let eventLoop : EventLoop
131
+ public var eventLoop : EventLoop {
132
+ self . storage. eventLoop
133
+ }
82
134
83
135
/// `ByteBufferAllocator` to allocate `ByteBuffer`
84
136
/// This is useful when implementing `EventLoopLambdaHandler`
85
- public let allocator : ByteBufferAllocator
137
+ public var allocator : ByteBufferAllocator {
138
+ self . storage. allocator
139
+ }
86
140
87
141
internal init ( requestID: String ,
88
142
traceID: String ,
@@ -92,22 +146,16 @@ extension Lambda {
92
146
clientContext: String ? = nil ,
93
147
logger: Logger ,
94
148
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)
111
159
}
112
160
113
161
public func getRemainingTime( ) -> TimeAmount {
0 commit comments