@@ -58,151 +58,149 @@ extension Lambda {
5858
5959// MARK: - Context
6060
61- extension Lambda {
62- /// Lambda runtime context.
63- /// The Lambda runtime generates and passes the `Context` to the Lambda handler as an argument.
64- public struct Context : CustomDebugStringConvertible {
65- final class _Storage {
66- var requestID : String
67- var traceID : String
68- var invokedFunctionARN : String
69- var deadline : DispatchWallTime
70- var cognitoIdentity : String ?
71- var clientContext : String ?
72- var logger : Logger
73- var eventLoop : EventLoop
74- var allocator : ByteBufferAllocator
75-
76- init (
77- requestID: String ,
78- traceID: String ,
79- invokedFunctionARN: String ,
80- deadline: DispatchWallTime ,
81- cognitoIdentity: String ? ,
82- clientContext: String ? ,
83- logger: Logger ,
84- eventLoop: EventLoop ,
85- allocator: ByteBufferAllocator
86- ) {
87- self . requestID = requestID
88- self . traceID = traceID
89- self . invokedFunctionARN = invokedFunctionARN
90- self . deadline = deadline
91- self . cognitoIdentity = cognitoIdentity
92- self . clientContext = clientContext
93- self . logger = logger
94- self . eventLoop = eventLoop
95- self . allocator = allocator
96- }
61+ /// Lambda runtime context.
62+ /// The Lambda runtime generates and passes the `Context` to the Lambda handler as an argument.
63+ public struct LambdaContext : CustomDebugStringConvertible {
64+ final class _Storage {
65+ var requestID : String
66+ var traceID : String
67+ var invokedFunctionARN : String
68+ var deadline : DispatchWallTime
69+ var cognitoIdentity : String ?
70+ var clientContext : String ?
71+ var logger : Logger
72+ var eventLoop : EventLoop
73+ var allocator : ByteBufferAllocator
74+
75+ init (
76+ requestID: String ,
77+ traceID: String ,
78+ invokedFunctionARN: String ,
79+ deadline: DispatchWallTime ,
80+ cognitoIdentity: String ? ,
81+ clientContext: String ? ,
82+ logger: Logger ,
83+ eventLoop: EventLoop ,
84+ allocator: ByteBufferAllocator
85+ ) {
86+ self . requestID = requestID
87+ self . traceID = traceID
88+ self . invokedFunctionARN = invokedFunctionARN
89+ self . deadline = deadline
90+ self . cognitoIdentity = cognitoIdentity
91+ self . clientContext = clientContext
92+ self . logger = logger
93+ self . eventLoop = eventLoop
94+ self . allocator = allocator
9795 }
96+ }
9897
99- private var storage : _Storage
98+ private var storage : _Storage
10099
101- /// The request ID, which identifies the request that triggered the function invocation.
102- public var requestID : String {
103- self . storage. requestID
104- }
100+ /// The request ID, which identifies the request that triggered the function invocation.
101+ public var requestID : String {
102+ self . storage. requestID
103+ }
105104
106- /// The AWS X-Ray tracing header.
107- public var traceID : String {
108- self . storage. traceID
109- }
105+ /// The AWS X-Ray tracing header.
106+ public var traceID : String {
107+ self . storage. traceID
108+ }
110109
111- /// The ARN of the Lambda function, version, or alias that's specified in the invocation.
112- public var invokedFunctionARN : String {
113- self . storage. invokedFunctionARN
114- }
110+ /// The ARN of the Lambda function, version, or alias that's specified in the invocation.
111+ public var invokedFunctionARN : String {
112+ self . storage. invokedFunctionARN
113+ }
115114
116- /// The timestamp that the function times out
117- public var deadline : DispatchWallTime {
118- self . storage. deadline
119- }
115+ /// The timestamp that the function times out
116+ public var deadline : DispatchWallTime {
117+ self . storage. deadline
118+ }
120119
121- /// For invocations from the AWS Mobile SDK, data about the Amazon Cognito identity provider.
122- public var cognitoIdentity : String ? {
123- self . storage. cognitoIdentity
124- }
120+ /// For invocations from the AWS Mobile SDK, data about the Amazon Cognito identity provider.
121+ public var cognitoIdentity : String ? {
122+ self . storage. cognitoIdentity
123+ }
125124
126- /// For invocations from the AWS Mobile SDK, data about the client application and device.
127- public var clientContext : String ? {
128- self . storage. clientContext
129- }
125+ /// For invocations from the AWS Mobile SDK, data about the client application and device.
126+ public var clientContext : String ? {
127+ self . storage. clientContext
128+ }
130129
131- /// `Logger` to log with
132- ///
133- /// - note: The `LogLevel` can be configured using the `LOG_LEVEL` environment variable.
134- public var logger : Logger {
135- self . storage. logger
136- }
130+ /// `Logger` to log with
131+ ///
132+ /// - note: The `LogLevel` can be configured using the `LOG_LEVEL` environment variable.
133+ public var logger : Logger {
134+ self . storage. logger
135+ }
137136
138- /// The `EventLoop` the Lambda is executed on. Use this to schedule work with.
139- /// This is useful when implementing the `EventLoopLambdaHandler` protocol.
140- ///
141- /// - note: The `EventLoop` is shared with the Lambda runtime engine and should be handled with extra care.
142- /// Most importantly the `EventLoop` must never be blocked.
143- public var eventLoop : EventLoop {
144- self . storage. eventLoop
145- }
137+ /// The `EventLoop` the Lambda is executed on. Use this to schedule work with.
138+ /// This is useful when implementing the `EventLoopLambdaHandler` protocol.
139+ ///
140+ /// - note: The `EventLoop` is shared with the Lambda runtime engine and should be handled with extra care.
141+ /// Most importantly the `EventLoop` must never be blocked.
142+ public var eventLoop : EventLoop {
143+ self . storage. eventLoop
144+ }
146145
147- /// `ByteBufferAllocator` to allocate `ByteBuffer`
148- /// This is useful when implementing `EventLoopLambdaHandler`
149- public var allocator : ByteBufferAllocator {
150- self . storage. allocator
151- }
146+ /// `ByteBufferAllocator` to allocate `ByteBuffer`
147+ /// This is useful when implementing `EventLoopLambdaHandler`
148+ public var allocator : ByteBufferAllocator {
149+ self . storage. allocator
150+ }
152151
153- init ( requestID: String ,
154- traceID: String ,
155- invokedFunctionARN: String ,
156- deadline: DispatchWallTime ,
157- cognitoIdentity: String ? = nil ,
158- clientContext: String ? = nil ,
159- logger: Logger ,
160- eventLoop: EventLoop ,
161- allocator: ByteBufferAllocator ) {
162- self . storage = _Storage (
163- requestID: requestID,
164- traceID: traceID,
165- invokedFunctionARN: invokedFunctionARN,
166- deadline: deadline,
167- cognitoIdentity: cognitoIdentity,
168- clientContext: clientContext,
169- logger: logger,
170- eventLoop: eventLoop,
171- allocator: allocator
172- )
173- }
152+ init ( requestID: String ,
153+ traceID: String ,
154+ invokedFunctionARN: String ,
155+ deadline: DispatchWallTime ,
156+ cognitoIdentity: String ? = nil ,
157+ clientContext: String ? = nil ,
158+ logger: Logger ,
159+ eventLoop: EventLoop ,
160+ allocator: ByteBufferAllocator ) {
161+ self . storage = _Storage (
162+ requestID: requestID,
163+ traceID: traceID,
164+ invokedFunctionARN: invokedFunctionARN,
165+ deadline: deadline,
166+ cognitoIdentity: cognitoIdentity,
167+ clientContext: clientContext,
168+ logger: logger,
169+ eventLoop: eventLoop,
170+ allocator: allocator
171+ )
172+ }
174173
175- public func getRemainingTime( ) -> TimeAmount {
176- let deadline = self . deadline. millisSinceEpoch
177- let now = DispatchWallTime . now ( ) . millisSinceEpoch
174+ public func getRemainingTime( ) -> TimeAmount {
175+ let deadline = self . deadline. millisSinceEpoch
176+ let now = DispatchWallTime . now ( ) . millisSinceEpoch
178177
179- let remaining = deadline - now
180- return . milliseconds( remaining)
181- }
178+ let remaining = deadline - now
179+ return . milliseconds( remaining)
180+ }
182181
183- public var debugDescription : String {
184- " \( Self . self) (requestID: \( self . requestID) , traceID: \( self . traceID) , invokedFunctionARN: \( self . invokedFunctionARN) , cognitoIdentity: \( self . cognitoIdentity ?? " nil " ) , clientContext: \( self . clientContext ?? " nil " ) , deadline: \( self . deadline) ) "
185- }
182+ public var debugDescription : String {
183+ " \( Self . self) (requestID: \( self . requestID) , traceID: \( self . traceID) , invokedFunctionARN: \( self . invokedFunctionARN) , cognitoIdentity: \( self . cognitoIdentity ?? " nil " ) , clientContext: \( self . clientContext ?? " nil " ) , deadline: \( self . deadline) ) "
184+ }
186185
187- /// This interface is not part of the public API and must not be used by adopters. This API is not part of semver versioning.
188- public static func __forTestsOnly(
189- requestID: String ,
190- traceID: String ,
191- invokedFunctionARN: String ,
192- timeout: DispatchTimeInterval ,
193- logger: Logger ,
194- eventLoop: EventLoop
195- ) -> Context {
196- Context (
197- requestID: requestID,
198- traceID: traceID,
199- invokedFunctionARN: invokedFunctionARN,
200- deadline: . now( ) + timeout,
201- logger: logger,
202- eventLoop: eventLoop,
203- allocator: ByteBufferAllocator ( )
204- )
205- }
186+ /// This interface is not part of the public API and must not be used by adopters. This API is not part of semver versioning.
187+ public static func __forTestsOnly(
188+ requestID: String ,
189+ traceID: String ,
190+ invokedFunctionARN: String ,
191+ timeout: DispatchTimeInterval ,
192+ logger: Logger ,
193+ eventLoop: EventLoop
194+ ) -> LambdaContext {
195+ LambdaContext (
196+ requestID: requestID,
197+ traceID: traceID,
198+ invokedFunctionARN: invokedFunctionARN,
199+ deadline: . now( ) + timeout,
200+ logger: logger,
201+ eventLoop: eventLoop,
202+ allocator: ByteBufferAllocator ( )
203+ )
206204 }
207205}
208206
0 commit comments