SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
SWIFT MICRO-SERVICES
AND AWSTECHNOLOGIES
Simon Pilkington
Senior Software Engineer
CoreTechnology
AmazonVideo
ABOUT ME
• 4 years helping architect, build and
maintain frameworks for Amazon.com
• Recently moved to CoreTechnology in
AmazonVideo
• Grew up in Melbourne,Australia
WHY SWIFT?
WHY IS JAVA PREVALENT?
• Not significant learning curve
• Harder to make mistakes than C++
• Enables higher developer velocity to create
WHY LOOK BEYOND JAVA?
Build Logic What's included
This package includes tools to help with:
• Code Coverage (JaCoco, PIT)
• Code Style (Checkstyle and matching IntelliJ formatter)
• Code Quality (FindBugs, PMD, Copy Paste Detector, JDepend).
CODE GENERATION FOR SWIFT SERVICE
• Code Generation of model objects, operation stubs and unit tests
• Use Codable conformance for serialization and de-serialization
• Swagger document can also be passed to Cloud Formation to create an API Gateway to
front the service.
Generated Code /**
Handler for the HelloWorld operation.
- Parameters:
- input: The validated HelloWorldRequest object being passed to this operation.
- context: The activities context provided for this operation.
- Returns: The HelloWorldResponse object to be passed back from the caller of this operation.
Will be validated before being returned to caller.
*/
func handleHelloWorld(input: HelloWorldModel.HellowWorldRequest,
context: HellowWorldActivitiesContext) -> HelloWorldModel.HellowWorldResponse {
return HelloWorldModel.HelloWorldResponse(greeting: "Hello (input.name)")
}
RUNTIME
• Initial proof of concept as a container running on ECS
• Using an implementation of IBM’s LoggerAPI to write logs to Cloudwatch
• Retrieve AWS credentials from the container with automatic credential
rotation
• Manages health checks, unresponsive containers are automatically
replaced
DATABASE SERIALIZATION
Code
Code
struct Fruit: Codable {
let fruitID: FruitID
let accessRole: AccessRole
let sweet: Int
let sour: Int
}
struct Location: Codable {
let locationID: LocationID
let fruitID: FruitID
let locationPath: String
let locationType: LocationType
let checksum: Int
let checksumType: ChecksumType
}
• Large datasets or fast concurrent access more suited to NOSQL
databases
• Database schema based around data access patterns to enable efficient
queries
• DynamoDb’s DynamoDBMapper in the Java AWS SDK
implements optimistic locking by managing an invisible row
version attribute
• Currently there is a pull request to implement polymorphic
tables similarly using inheritance and managing an invisible
subclass attribute
But Inheritance…
PROTOCOLSTOTHE RESCUE!
Probably look familiar
Swift Language public protocol Encodable {
public func encode(to encoder: Encoder) throws
}
public protocol Decodable {
public init(from decoder: Decoder) throws
}
public typealias Codable = Decodable & Encodable
DYNAMO SPECIFIC ENCODING
JSON {
"Name": {"S": "Citrus"}
"Description": {"S": "They’re alright."}
}
DynamoDb
Codable
Object
Codable
Object
DynamoEncoder JSONEncoder
DynamoDecoder JSONDecoder
OPERATION IMPLEMENTATION
Code func handleRegisterFamily(input: FruitModel.FamilyAttributes,
context: FruitActivitiesContext)
throws -> FruitModel.FamilyIdentity {
let currentID = context.idGenerator()
let partitionKey = familyKeyPrefix + currentID
let key = DefaultIdentityCompositePrimaryKey(partitionKey: partitionKey,
sortKey: partitionKey)
let newDatabaseRow = TypedDatabaseItem.newItem(withKey: key, andValue: input)
try context.dynamoClient.putItem(newDatabaseRow)
return FruitModel.FamilyIdentity(familyID: partitionKey)
}
TYPEDDATABASEITEM
• Handles row type, versioning, create and last modified timestamps.
• Accepts a row value conforming to Codable
• By default a newTypedDatabaseItem will fail to overwrite an existing
row
• CompositePrimaryKey defines row identity - partition and sort keys;
generic in a protocol that defines the key attribute names
Library Code
public struct TypedDatabaseItem<RowIdentity : DynamoRowIdentity, RowType : Codable>: Codable {
...
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
let storedRowTypeName = try values.decode(String.self, forKey: .rowType)
self.createDate = try values.decode(Date.self, forKey: .createDate)
// get the type that is being requested to be decoded into
let requestedRowTypeName = getTypeRowIdentity(type: RowType.self)
// if the stored rowType is not what we should attempt to decode into
guard storedRowTypeName == requestedRowTypeName else {
// throw an error to avoid accidentally decoding into the incorrect type
throw SwiftDynamoError.typeMismatch(expected: storedRowTypeName,
provided: requestedRowTypeName)
}
self.compositePrimaryKey = try CompositePrimaryKey(from: decoder)
self.rowStatus = try RowStatus(from: decoder)
self.rowValue = try RowType(from: decoder)
self.canOverwriteExistingRow = false
self.onlyOverwriteVersionNumber = nil
}
}
• createUpdatedItem function creates a new instance with updated last
modified timestamp and incremented row version.
• By default will fail to overwrite a row version other than the version
it was created from
Code let updatedFruitRow =
fruitDatabaseItem.createUpdatedItem(withValue: updatedFruitAttributes)
do {
try context.dynamoClient.putItem(updatedAccountRow)
} catch SwiftDynamoError.conditionalCheckFailed(_) {
// handle the error
}
BUT WHAT ABOUT QUERIES?
AGAIN PROTOCOLSTOTHE RESCUE
• Similar toTypedDatabaseItem but returns a row type of Codable, de-
serialized according to the type specified in the data row
Library Code public protocol PossibleItemTypes {
static var types: [Codable.Type] { get }
}
public struct PolymorphicDatabaseItem<RowIdentity : DynamoRowIdentity,
PossibleTypes : PossibleItemTypes> : Decodable {
...
}
A FINAL ODETO PROTOCOLS
Generated Code public protocol LocationShape {
associatedtype LocationTypeType : CustomStringConvertible
associatedtype ChecksumTypeType : CustomStringConvertible
var locationPath: String { get }
var locationType: LocationTypeType { get }
var checksum: String { get }
var checksumType: ChecksumTypeType { get }
func asFruitModelLocation() throws -> Location
}
Code extension SaladModel.Location : FruitModel.LocationShape {}
...
let location = try input.location.asFruitModelLocation()

Weitere ähnliche Inhalte

Was ist angesagt?

Groovy on Grails by Ziya Askerov
Groovy on Grails by Ziya AskerovGroovy on Grails by Ziya Askerov
Groovy on Grails by Ziya AskerovVuqar Suleymanov
 
Realm of the Mobile Database: an introduction to Realm
Realm of the Mobile Database: an introduction to RealmRealm of the Mobile Database: an introduction to Realm
Realm of the Mobile Database: an introduction to RealmMartin Grider
 
Useful and Practical Functionalities in Realm
Useful and Practical Functionalities in RealmUseful and Practical Functionalities in Realm
Useful and Practical Functionalities in RealmYusuke Kita
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scalatod esking
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!scalaconfjp
 
Slot Composition
Slot CompositionSlot Composition
Slot CompositionESUG
 
Type Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesType Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesmametter
 
Android course session 5 (Threads & socket)
Android course session 5 (Threads & socket)Android course session 5 (Threads & socket)
Android course session 5 (Threads & socket)Keroles M.Yakoub
 
Introducing Troy Scala IO 2016
Introducing Troy Scala IO 2016Introducing Troy Scala IO 2016
Introducing Troy Scala IO 2016Tamer Abdul-Radi
 
Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with RealmChristian Melchior
 

Was ist angesagt? (20)

Groovy on Grails by Ziya Askerov
Groovy on Grails by Ziya AskerovGroovy on Grails by Ziya Askerov
Groovy on Grails by Ziya Askerov
 
Realm of the Mobile Database: an introduction to Realm
Realm of the Mobile Database: an introduction to RealmRealm of the Mobile Database: an introduction to Realm
Realm of the Mobile Database: an introduction to Realm
 
Useful and Practical Functionalities in Realm
Useful and Practical Functionalities in RealmUseful and Practical Functionalities in Realm
Useful and Practical Functionalities in Realm
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Guild Prototype
Guild PrototypeGuild Prototype
Guild Prototype
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
 
PHP7
PHP7PHP7
PHP7
 
Slot Composition
Slot CompositionSlot Composition
Slot Composition
 
Slot Composition
Slot CompositionSlot Composition
Slot Composition
 
jTransfo quickie at JavaZone 2015
jTransfo quickie at JavaZone 2015jTransfo quickie at JavaZone 2015
jTransfo quickie at JavaZone 2015
 
Type Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesType Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signatures
 
JavaScript Good Practices
JavaScript Good PracticesJavaScript Good Practices
JavaScript Good Practices
 
Node.js code tracing
Node.js code tracingNode.js code tracing
Node.js code tracing
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
Android course session 5 (Threads & socket)
Android course session 5 (Threads & socket)Android course session 5 (Threads & socket)
Android course session 5 (Threads & socket)
 
Realm
RealmRealm
Realm
 
Introducing Troy Scala IO 2016
Introducing Troy Scala IO 2016Introducing Troy Scala IO 2016
Introducing Troy Scala IO 2016
 
OOP in JavaScript
OOP in JavaScriptOOP in JavaScript
OOP in JavaScript
 
Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with Realm
 
Children of Ruby
Children of RubyChildren of Ruby
Children of Ruby
 

Ähnlich wie Swift Micro-services and AWS Technologies

How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseSpeedment, Inc.
 
Silicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSilicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSpeedment, Inc.
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...Malin Weiss
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...Speedment, Inc.
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldChristian Melchior
 
Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David SzakallasDatabricks
 
Jdbc presentation
Jdbc presentationJdbc presentation
Jdbc presentationnrjoshiee
 
First class Variables in Pharo
First class Variables in PharoFirst class Variables in Pharo
First class Variables in PharoESUG
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffJAX London
 
Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overviewscdhruv5
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele RialdiCodeFest
 
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-FormatsBig Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-FormatsGuido Schmutz
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1Mohammad Qureshi
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsDaniel Ballinger
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 

Ähnlich wie Swift Micro-services and AWS Technologies (20)

How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your database
 
Silicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSilicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your database
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
 
Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David Szakallas
 
Jdbc presentation
Jdbc presentationJdbc presentation
Jdbc presentation
 
First class Variables in Pharo
First class Variables in PharoFirst class Variables in Pharo
First class Variables in Pharo
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overview
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-FormatsBig Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
 
Grails
GrailsGrails
Grails
 
Grails
GrailsGrails
Grails
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service Clients
 
Naver_alternative_to_jpa
Naver_alternative_to_jpaNaver_alternative_to_jpa
Naver_alternative_to_jpa
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 

Kürzlich hochgeladen

Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 

Kürzlich hochgeladen (20)

Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 

Swift Micro-services and AWS Technologies

  • 1. SWIFT MICRO-SERVICES AND AWSTECHNOLOGIES Simon Pilkington Senior Software Engineer CoreTechnology AmazonVideo
  • 2. ABOUT ME • 4 years helping architect, build and maintain frameworks for Amazon.com • Recently moved to CoreTechnology in AmazonVideo • Grew up in Melbourne,Australia
  • 4. WHY IS JAVA PREVALENT? • Not significant learning curve • Harder to make mistakes than C++ • Enables higher developer velocity to create
  • 5. WHY LOOK BEYOND JAVA? Build Logic What's included This package includes tools to help with: • Code Coverage (JaCoco, PIT) • Code Style (Checkstyle and matching IntelliJ formatter) • Code Quality (FindBugs, PMD, Copy Paste Detector, JDepend).
  • 6. CODE GENERATION FOR SWIFT SERVICE • Code Generation of model objects, operation stubs and unit tests • Use Codable conformance for serialization and de-serialization • Swagger document can also be passed to Cloud Formation to create an API Gateway to front the service. Generated Code /** Handler for the HelloWorld operation. - Parameters: - input: The validated HelloWorldRequest object being passed to this operation. - context: The activities context provided for this operation. - Returns: The HelloWorldResponse object to be passed back from the caller of this operation. Will be validated before being returned to caller. */ func handleHelloWorld(input: HelloWorldModel.HellowWorldRequest, context: HellowWorldActivitiesContext) -> HelloWorldModel.HellowWorldResponse { return HelloWorldModel.HelloWorldResponse(greeting: "Hello (input.name)") }
  • 7. RUNTIME • Initial proof of concept as a container running on ECS • Using an implementation of IBM’s LoggerAPI to write logs to Cloudwatch • Retrieve AWS credentials from the container with automatic credential rotation • Manages health checks, unresponsive containers are automatically replaced
  • 8. DATABASE SERIALIZATION Code Code struct Fruit: Codable { let fruitID: FruitID let accessRole: AccessRole let sweet: Int let sour: Int } struct Location: Codable { let locationID: LocationID let fruitID: FruitID let locationPath: String let locationType: LocationType let checksum: Int let checksumType: ChecksumType }
  • 9. • Large datasets or fast concurrent access more suited to NOSQL databases • Database schema based around data access patterns to enable efficient queries
  • 10. • DynamoDb’s DynamoDBMapper in the Java AWS SDK implements optimistic locking by managing an invisible row version attribute • Currently there is a pull request to implement polymorphic tables similarly using inheritance and managing an invisible subclass attribute
  • 12. PROTOCOLSTOTHE RESCUE! Probably look familiar Swift Language public protocol Encodable { public func encode(to encoder: Encoder) throws } public protocol Decodable { public init(from decoder: Decoder) throws } public typealias Codable = Decodable & Encodable
  • 13. DYNAMO SPECIFIC ENCODING JSON { "Name": {"S": "Citrus"} "Description": {"S": "They’re alright."} } DynamoDb Codable Object Codable Object DynamoEncoder JSONEncoder DynamoDecoder JSONDecoder
  • 14. OPERATION IMPLEMENTATION Code func handleRegisterFamily(input: FruitModel.FamilyAttributes, context: FruitActivitiesContext) throws -> FruitModel.FamilyIdentity { let currentID = context.idGenerator() let partitionKey = familyKeyPrefix + currentID let key = DefaultIdentityCompositePrimaryKey(partitionKey: partitionKey, sortKey: partitionKey) let newDatabaseRow = TypedDatabaseItem.newItem(withKey: key, andValue: input) try context.dynamoClient.putItem(newDatabaseRow) return FruitModel.FamilyIdentity(familyID: partitionKey) }
  • 15. TYPEDDATABASEITEM • Handles row type, versioning, create and last modified timestamps. • Accepts a row value conforming to Codable • By default a newTypedDatabaseItem will fail to overwrite an existing row • CompositePrimaryKey defines row identity - partition and sort keys; generic in a protocol that defines the key attribute names
  • 16. Library Code public struct TypedDatabaseItem<RowIdentity : DynamoRowIdentity, RowType : Codable>: Codable { ... public init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) let storedRowTypeName = try values.decode(String.self, forKey: .rowType) self.createDate = try values.decode(Date.self, forKey: .createDate) // get the type that is being requested to be decoded into let requestedRowTypeName = getTypeRowIdentity(type: RowType.self) // if the stored rowType is not what we should attempt to decode into guard storedRowTypeName == requestedRowTypeName else { // throw an error to avoid accidentally decoding into the incorrect type throw SwiftDynamoError.typeMismatch(expected: storedRowTypeName, provided: requestedRowTypeName) } self.compositePrimaryKey = try CompositePrimaryKey(from: decoder) self.rowStatus = try RowStatus(from: decoder) self.rowValue = try RowType(from: decoder) self.canOverwriteExistingRow = false self.onlyOverwriteVersionNumber = nil } }
  • 17. • createUpdatedItem function creates a new instance with updated last modified timestamp and incremented row version. • By default will fail to overwrite a row version other than the version it was created from Code let updatedFruitRow = fruitDatabaseItem.createUpdatedItem(withValue: updatedFruitAttributes) do { try context.dynamoClient.putItem(updatedAccountRow) } catch SwiftDynamoError.conditionalCheckFailed(_) { // handle the error }
  • 18. BUT WHAT ABOUT QUERIES?
  • 19. AGAIN PROTOCOLSTOTHE RESCUE • Similar toTypedDatabaseItem but returns a row type of Codable, de- serialized according to the type specified in the data row Library Code public protocol PossibleItemTypes { static var types: [Codable.Type] { get } } public struct PolymorphicDatabaseItem<RowIdentity : DynamoRowIdentity, PossibleTypes : PossibleItemTypes> : Decodable { ... }
  • 20. A FINAL ODETO PROTOCOLS Generated Code public protocol LocationShape { associatedtype LocationTypeType : CustomStringConvertible associatedtype ChecksumTypeType : CustomStringConvertible var locationPath: String { get } var locationType: LocationTypeType { get } var checksum: String { get } var checksumType: ChecksumTypeType { get } func asFruitModelLocation() throws -> Location } Code extension SaladModel.Location : FruitModel.LocationShape {} ... let location = try input.location.asFruitModelLocation()