Created
July 12, 2020 11:48
-
-
Save alfianlosari/caa05191b84c6cdb9b354e9bdde34f77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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