Skip to content

Commit 46ba794

Browse files
Rename LambdaAPI to Product API
Fix ProductLambda init
1 parent 21ccb0d commit 46ba794

11 files changed

+16
-10
lines changed

Examples/LambdaFunctions/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let package = Package(
1919
// fully featured example with domain specific business logic
2020
.executable(name: "CurrencyExchange", targets: ["CurrencyExchange"]),
2121
// Full REST API Example using APIGateway, Lambda, DynamoDB
22-
.executable(name: "LambdaAPI", targets: ["LambdaAPI"]),
22+
.executable(name: "ProductAPI", targets: ["ProductAPI"]),
2323
],
2424
dependencies: [
2525
// this is the dependency on the swift-aws-lambda-runtime library
@@ -50,7 +50,7 @@ let package = Package(
5050
.target(name: "CurrencyExchange", dependencies: [
5151
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
5252
]),
53-
.target(name: "LambdaAPI", dependencies: [
53+
.target(name: "ProductAPI", dependencies: [
5454
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
5555
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-runtime"),
5656
.product(name: "AWSDynamoDB", package: "aws-sdk-swift"),

Examples/LambdaFunctions/Sources/LambdaAPI/ProductLambda.swift renamed to Examples/LambdaFunctions/Sources/ProductAPI/ProductLambda.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ struct ProductLambda: LambdaHandler {
6565
}
6666

6767
static func tableName() throws -> String {
68-
guard let tableName = ProcessInfo.processInfo.environment["PRODUCTS_TABLE_NAME"] else {
68+
guard let tableName = Lambda.env("PRODUCTS_TABLE_NAME") else {
6969
throw APIError.tableNameNotFound
7070
}
7171
return tableName
7272
}
7373

74-
init(eventLoop: EventLoop) {
74+
init(context: Lambda.InitializationContext) {
7575

7676
let handler = Lambda.env("_HANDLER") ?? ""
7777
self.operation = Operation(rawValue: handler) ?? .unknown
@@ -80,11 +80,17 @@ struct ProductLambda: LambdaHandler {
8080
logger.info("\(Self.currentRegion())")
8181

8282
let lambdaRuntimeTimeout: TimeAmount = .seconds(dbTimeout)
83-
let timeout = HTTPClient.Configuration.Timeout(connect: lambdaRuntimeTimeout,
84-
read: lambdaRuntimeTimeout)
83+
let timeout = HTTPClient.Configuration.Timeout(
84+
connect: lambdaRuntimeTimeout,
85+
read: lambdaRuntimeTimeout
86+
)
87+
8588
let configuration = HTTPClient.Configuration(timeout: timeout)
86-
self.httpClient = HTTPClient(eventLoopGroupProvider: .createNew, configuration: configuration)
87-
89+
self.httpClient = HTTPClient(
90+
eventLoopGroupProvider: .shared(context.eventLoop),
91+
configuration: configuration
92+
)
93+
8894
self.db = AWSDynamoDB.DynamoDB(region: region, httpClientProvider: .shared(self.httpClient))
8995
logger.info("DynamoDB")
9096

Examples/LambdaFunctions/scripts/SAM/LambdaAPI-template.yml renamed to Examples/LambdaFunctions/scripts/SAM/ProductAPI-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Globals:
66
Function:
77
MemorySize: 256
88
Runtime: provided
9-
CodeUri: ../../.build/lambda/LambdaAPI/lambda.zip
9+
CodeUri: ../../.build/lambda/ProductAPI/lambda.zip
1010
Environment:
1111
Variables:
1212
PRODUCTS_TABLE_NAME: product-table-sam

Examples/LambdaFunctions/scripts/serverless/LambdaAPI-template.yml renamed to Examples/LambdaFunctions/scripts/serverless/ProductAPI-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ service: swift-awslambda-runtime-api
33
# package:
44
# individually: true
55
package:
6-
artifact: .build/lambda/LambdaAPI/lambda.zip
6+
artifact: .build/lambda/ProductAPI/lambda.zip
77

88
provider:
99
name: aws

0 commit comments

Comments
 (0)