Skip to content

Instantly share code, notes, and snippets.

@alfianlosari
Created July 12, 2020 11:48
Show Gist options
  • Select an option

  • Save alfianlosari/caa05191b84c6cdb9b354e9bdde34f77 to your computer and use it in GitHub Desktop.

Select an option

Save alfianlosari/caa05191b84c6cdb9b354e9bdde34f77 to your computer and use it in GitHub Desktop.
struct TodoLamdaHandler: EventLoopLambdaHandler {
//...
init(context: Lambda.InitializationContext) throws {
// HTTP Client Setup
let timeout = HTTPClient.Configuration.Timeout(
connect: .seconds(30),
read: .seconds(30)
)
let httpClient = HTTPClient(
eventLoopGroupProvider: .shared(context.eventLoop),
configuration: HTTPClient.Configuration(timeout: timeout)
)
// Retrieving Environment Variables for TableName and Region
let tableName = Lambda.env("TODOS_TABLE_NAME") ?? ""
let region: Region
if let envRegion = Lambda.env("AWS_REGION") {
region = Region(rawValue: envRegion)
} else {
region = .uswest2
}
// Initializing DynamoDB and TodoService
let db = AWSDynamoDB.DynamoDB(region: region, httpClientProvider: .shared(httpClient))
let todoService = TodoService(db: db, tableName: tableName)
// Assign to instance properties
self.httpClient = httpClient
self.db = db
self.todoService = todoService
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment