You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently this blog repo includes the source code for the Swift Lambda function that processes events incoming from GitHub Actions via SQS. As I write this, I am working on the code for parsing these events, using Codable Swift structures.
Package Structure
The package has three modules:
IssueProcessorLambda: lambda function code
Blog: main logic for parsing and processing events
BlogTests: unit tests for the main logic
By moving the logic outside of the lambda function module, I can minimize the code in the lambda binary, which cannot be unit tested.
As mentioned, the lambda handler is pretty thin. The goal is to put all logic on Blog (or other modules) so it can be unit tested, and fully independent from AWS Lambda.
structHandler:LambdaHandler{typealiasIn=SQS.EventtypealiasOut=String// Response typeletparser:IssueParserletprocessor:IssueProcessor/// Business logic is initialized during lambda cold start/// - Parameter context: Lambda initialization context, provided by AWSinit(context:Lambda.InitializationContext){
parser =IssueParser(logger: context.logger)
processor =IssueProcessor(logger: context.logger)}func handle(context:Lambda.Context, event:In, callback:@escaping(Result<Out,Error>)->Void){do{
for message in event.records {letgithubContext=try parser.parse(eventPayload: message.body)try processor.process(githubEvent: githubContext.event)}callback(.success(""))}catch{callback(.failure(error))}}}Lambda.run(Handler.init)
Codable Structures
So far, my structures look like this (no need to parse all fields from the event):
The IssueParser object is listed below. Most of the code is to prepare the JSONDecoder to automatically convert property names from snake_case to camelCase and to automatically parse ISO8601 dates.
eneko
changed the title
Parsing GitHub events on AWS Lambda (in Swift)
Blog Engine: Parsing GitHub events on AWS Lambda (in Swift)
Dec 24, 2020
eneko
changed the title
Blog Engine: Parsing GitHub events on AWS Lambda (in Swift)
Blog Engine - Parsing GitHub events on AWS Lambda (in Swift)
Dec 24, 2020
Currently this blog repo includes the source code for the Swift Lambda function that processes events incoming from GitHub Actions via SQS. As I write this, I am working on the code for parsing these events, using
Codable
Swift structures.Package Structure
The package has three modules:
By moving the logic outside of the lambda function module, I can minimize the code in the lambda binary, which cannot be unit tested.
Package Dependencies
Swift Lambda Runtime and Swift Log are the main dependencies used:
Lambda Source Code
As mentioned, the lambda handler is pretty thin. The goal is to put all logic on
Blog
(or other modules) so it can be unit tested, and fully independent from AWS Lambda.Codable Structures
So far, my structures look like this (no need to parse all fields from the event):
The
IssueParser
object is listed below. Most of the code is to prepare theJSONDecoder
to automatically convert property names fromsnake_case
tocamelCase
and to automatically parse ISO8601 dates.Finally,
IssueProcessor
will handle the rest, right now it just dumps the event to CloudWatch, so I can verify things are working as expected.Stay tuned for more!
Update
Here is the screenshot with the above article dumped in CloudWatch logs 🎉
The text was updated successfully, but these errors were encountered: