Skip to content

Commit 6e91d71

Browse files
committed
Rename Lambda.Context to LambdaContext
1 parent afab510 commit 6e91d71

File tree

21 files changed

+223
-213
lines changed

21 files changed

+223
-213
lines changed

Examples/Benchmark/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct MyLambda: EventLoopLambdaHandler {
2424
typealias Event = String
2525
typealias Output = String
2626

27-
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<String> {
27+
func handle(_ event: String, context: LambdaContext) -> EventLoopFuture<String> {
2828
context.eventLoop.makeSucceededFuture("hello, world!")
2929
}
3030
}

Examples/Deployment/Sources/Benchmark/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct BenchmarkHandler: EventLoopLambdaHandler {
2424
typealias Event = String
2525
typealias Output = String
2626

27-
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<String> {
27+
func handle(_ event: String, context: LambdaContext) -> EventLoopFuture<String> {
2828
context.eventLoop.makeSucceededFuture("hello, world!")
2929
}
3030
}

Examples/Deployment/Sources/HelloWorld/HelloWorldHandler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct HelloWorldHandler: LambdaHandler {
2424
// setup your resources that you want to reuse here.
2525
}
2626

27-
func handle(_ event: String, context: Lambda.Context) async throws -> String {
27+
func handle(_ event: String, context: LambdaContext) async throws -> String {
2828
"hello, world"
2929
}
3030
}

Examples/Echo/Lambda.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct MyLambda: LambdaHandler {
2525
// setup your resources that you want to reuse for every invocation here.
2626
}
2727

28-
func handle(_ input: String, context: Lambda.Context) async throws -> String {
28+
func handle(_ input: String, context: LambdaContext) async throws -> String {
2929
// as an example, respond with the input's reversed
3030
String(input.reversed())
3131
}

Examples/ErrorHandling/Lambda.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct MyLambda: LambdaHandler {
2323

2424
init(context: Lambda.InitializationContext) async throws {}
2525

26-
func handle(_ request: Request, context: Lambda.Context) async throws -> Response {
26+
func handle(_ request: Request, context: LambdaContext) async throws -> Response {
2727
// switch over the error type "requested" by the request, and trigger such error accordingly
2828
switch request.error {
2929
// no error here!

Examples/Foundation/Lambda.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct MyLambda: LambdaHandler {
3535
self.calculator = ExchangeRatesCalculator()
3636
}
3737

38-
func handle(_ event: Request, context: Lambda.Context) async throws -> [Exchange] {
38+
func handle(_ event: Request, context: LambdaContext) async throws -> [Exchange] {
3939
try await withCheckedThrowingContinuation { continuation in
4040
self.calculator.run(logger: context.logger) { result in
4141
switch result {

Examples/JSON/Lambda.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct MyLambda: LambdaHandler {
3434
// setup your resources that you want to reuse for every invocation here.
3535
}
3636

37-
func handle(_ event: Request, context: Lambda.Context) async throws -> Response {
37+
func handle(_ event: Request, context: LambdaContext) async throws -> Response {
3838
// as an example, respond with the input event's reversed body
3939
Response(body: String(event.body.reversed()))
4040
}

Examples/LocalDebugging/MyLambda/Lambda.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct MyLambda: LambdaHandler {
2727
// setup your resources that you want to reuse for every invocation here.
2828
}
2929

30-
func handle(_ request: Request, context: Lambda.Context) async throws -> Response {
30+
func handle(_ request: Request, context: LambdaContext) async throws -> Response {
3131
// TODO: something useful
3232
Response(message: "Hello, \(request.name)!")
3333
}

Examples/Testing/Sources/Lambda.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct MyLambda: LambdaHandler {
2525
// setup your resources that you want to reuse for every invocation here.
2626
}
2727

28-
func handle(_ event: String, context: Lambda.Context) async throws -> String {
28+
func handle(_ event: String, context: LambdaContext) async throws -> String {
2929
// as an example, respond with the event's reversed body
3030
String(event.reversed())
3131
}

Sources/AWSLambdaRuntime/Context+Foundation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import AWSLambdaRuntimeCore
1616
import struct Foundation.Date
1717

18-
extension Lambda.Context {
18+
extension LambdaContext {
1919
var deadlineDate: Date {
2020
let secondsSinceEpoch = Double(Int64(bitPattern: self.deadline.rawValue)) / -1_000_000_000
2121
return Date(timeIntervalSince1970: secondsSinceEpoch)

Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import NIOPosix
2424
// For example:
2525
//
2626
// try Lambda.withLocalServer {
27-
// Lambda.run { (context: Lambda.Context, event: String, callback: @escaping (Result<String, Error>) -> Void) in
27+
// Lambda.run { (context: LambdaContext, event: String, callback: @escaping (Result<String, Error>) -> Void) in
2828
// callback(.success("Hello, \(event)!"))
2929
// }
3030
// }

Sources/AWSLambdaRuntimeCore/LambdaContext.swift

+127-129
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)